Prediction of the stability of theMn+1AXnphases from first principles