Experimental and theoretical study of superconductor-ferromagnet-superconductor junctions (SFS junctions) showed that, in a certain range of parameters (e.g., the length of the ferromagnet dF, the exchange field Eex), the ground state of the SFS junction corresponds to a superconducting phase difference π or 0. The phase diagram of an SFS junction with respect to π and 0 states is investigated in this letter in Eex, dF, T space. It is shown that the phase diagram is very sensitive to the geometry of the system, in particular, to the amount of disorder in the junction.