The nine-valence-electron HMgNand HNMghave been investigated for the first time theoretically using complete active space self-consistent field (CASSCF) and multiconfiguration second-order perturbation theory (CASPT2) methods in conjunction with the contracted atomic natural orbital (ANO) basis sets. The structures of the low-lying electronic states of HMgNand HNMgwere predicted. The possible unimolecular conversions between HMgNand HNMgwere discussed. The calculated results indicated that the ground-state of HMgNis linear, while the ground-state HNMgis bent, which is in contradiction to the Walsh rules, which predict linear structures for HXY systems containing 10 or fewer valence electrons.