program works, but only for matrix of n*n size, not n*m size