Take the block matrix over $\mathbb{Q}$ defined by
m2 = block_matrix([[m[i,j].matrix() for j in range(M.ncols())] for i in range(M.nrows())])

and divide its rank by K.degree().
P.S. To get random matrices of lower rank you can use e.g. M.random_element(density=0.1).