Back to the Problem
Row-reduce modulo the prime; the rank is the number of nonzero pivot rows.
Complexity: O(N·M·min(N,M))