Structural and vibrational stability of M and Z phases of silicon and germanium from first principles