Using the evolutionary crystal structure prediction algorithm USPEX, we identify the compositions and crystal structures of thermodynamically stable compounds in the Fe-S system at pressures in the range of 100-400 GPa. We find that at pressures in the Earth's solid inner core (330-364 GPa) two compounds are stable - Fe2S and FeS. In equilibrium with iron, only Fe2S can exist in the inner core. Using the equation of state of Fe2S, we find that, in order to reproduce the density of the inner core by adding sulfur alone, 10.6-13.7 mol. % (6.4-8.4 wt.%) sulfur is needed. An analogous calculation for silicon (where the only stable compound at inner core pressures is FeSi) reproduces the density of the inner core with 9.0-11.8 mol.% (4.8-6.3 wt.%) silicon. In both cases, a virtually identical mean atomic mass M in the range of 52.6-53.3 results for the inner core, which is much higher than M = 49.3 inferred for the inner core from Birch's law. In the case of oxygen (allowing for the equilibrium coexistence of suboxide Fe20 with iron under core conditions), the inner core density can be explained by the oxygen content of 13.2-17.2 mol.% (4.2-5.6 wt.%), which corresponds to M between 49.0 and 50.6. Combining our results and previous work, we arrive at four preferred compositional models of the Earth's inner core (in mol.%): (i) 86% (Fe+Ni)+14% C; (ii) 84% (Fe + Ni) +16% O; (iii) 84% (Fe + Ni) + 7% S+ 9% H; (iv) 85 % (Fe + Ni) + 6 % Si + 9 % H.