User blog comment:Mango523WNR/Feb 2,2020/@comment-39128220-20200202123032/@comment-35470197-20200202143050

I meant the latter one.

There are n^m Blocks in the matrix. At the first step, you can start from any position (n^m patterns). At the second step, you can choose positions next to the first position (not greater than (n^m)-1 patterns). At the third step, you can choose positions next to the second position (not greater than (n^m)-2 patterns). Repeating the computation, the total number of methods is bounded by (n^m)!.