The Josephson energy of two superconducting islands containing Majorana fermions is a 4pi-periodic function of the superconducting phase difference. If the islands have a small capacitance, their ground state energy is governed by the competition of Josephson and charging energies. We calculate this ground state energy in a ring geometry, as a function of the flux -Phi- enclosed by the ring, and show that the dependence on the Aharonov-Bohm phase 2ePhi/hbar remains 4pi-periodic regardless of the ratio of charging and Josephson energies - provided that the entire ring is in a topologically nontrivial state. If part of the ring is topologically trivial, then the charging energy induces quantum phase slips that restore the usual 2pi-periodicity.