Completed algorithm to find matrix M.

Still have to find the values of matrix B to get the value of matrix N.