Multiphoton ionization of magnesium and calcium atoms by short and intense laser pulses