Structural stability of Mn-doped GaInAs and GaInN alloys