Calculate matrix N power of M