Matrix rotation sort Lets define a non-empty, unsorted and finite matrix with unique numbers as follow:
 $$N = \begin{Bmatrix} 4&amp;5&amp;7\\1&amp;3&amp;6 \end{Bmatrix}$$

Lets define 4 matrix moves as:


↑* (up): Moves a column up
↓* (down): Moves a column down
→* (right): Moves a row to the right 
←* (left): Moves a row to the left


The asterisk(*) represents the column/row that is affected by the move (It can be 0-indexed or 1-indexed. Up to you. Please state which one in your answer).



The challenge is, using above moves, sort the matrix in a ascendant order (being the top left corner the lowest and the bottom right corner the highest).

Example

Input:
$$N=\begin{Bmatrix}4&amp;2&amp;3\\1&amp;5&amp;6 \end{Bmatrix}$$
Possible Output: ↑0 or ↓0. (Notice any of those moves can sort the matrix so both answer are correct)



Input:
$$N=\begin{Bmatrix}2&amp;3&amp;1\\4&amp;5&amp;6 \end{Bmatrix}$$
Possible Output: →0



Input (Example test case):
 $$N = \begin{Bmatrix} 4&amp;5&amp;7\\1&amp;3&amp;6 \end{Bmatrix}$$
Possible Output: ↑0↑1←1↑2



Input:
$$N = \begin{Bmatrix} 5&amp;9&amp;6\\ 8&amp;2&amp;4\\ 1&amp;7&amp;3 \end{Bmatrix}$$
Possible Output:
↑0↑2→0→2↑0→2↑1↑2←1



Input:
$$N = \begin{Bmatrix} 1 &amp; 27 &amp; 28 &amp; 29 &amp; 6 \\10 &amp; 2 &amp; 3 &amp; 4 &amp; 5 \\17 &amp; 7 &amp; 8 &amp; 13 &amp; 9 \\15 &amp; 11 &amp; 12 &amp; 18 &amp; 14 \\26 &amp; 16 &amp; 21 &amp; 19 &amp; 20 \\30 &amp; 22 &amp; 23 &amp; 24 &amp; 25  \end{Bmatrix}$$
Possible Output:
↑2↑1←3→0←3↓0←0←2→3↑3↑4



Input:
$$N = \begin{Bmatrix} 1  \end{Bmatrix} $$
Output:
 or any move



Input: 
$$N = \begin{Bmatrix} 1&amp;2\\3&amp;4  \end{Bmatrix} $$
Output:




Notes


There can be different correct outputs (there don't need to be necessarily the same as the test cases or the shortest one)
You can assume it will be always a way to order the matrix
Edges connects (like pacman :v)
There wont be a matrix with more than 9 columns or/and rows
Assume matrix contains only positive non-zero unique integers
You can use any 4 distinct values other than numbers to represent the moves (in case of that, please state that in your answer)
Column/row can be 0 or 1 indexed
Winning criteria code-golf




Extra test cases are always welcome
JavaScript (ES6),  226  219 bytes
Brute force search, using right (&quot;R&quot;) and down (&quot;D&quot;) moves.
Returns either a string describing the moves, or an empty array if the input matrix is already sorted. Columns and rows in the output are 0-indexed.

f=(m,M=2)=&gt;(g=(s,m)=&gt;m[S='some'](p=r=&gt;r[S](x=&gt;p&gt;(p=x)))?!s[M]&amp;&amp;m[0][S]((_,x,a)=&gt;g(s+'D'+x,m.map(([...r],y)=&gt;(r[x]=(m[y+1]||a)[x])&amp;&amp;r)))|m[S]((_,y)=&gt;g(s+'R'+y,m.map(([...r])=&gt;y--?r:[r.pop(),...r]))):o=s)([],m)?o:f(m,M+2)

Try it online!
Commented
f =                              // f = main recursive function taking:
(m, M = 2) =&gt; (                  //   m[] = input matrix; M = maximum length of the solution
  g =                            // g = recursive solver taking:
  (s, m) =&gt;                      //   s = solution, m[] = current matrix
    m[S = 'some'](p =            // we first test whether m[] is sorted
      r =&gt;                       // by iterating on each row
        r[S](x =&gt;                // and each column
          p &gt; (p = x)            // and comparing each cell x with the previous cell p
        )                        //
    ) ?                          // if the matrix is not sorted:
      !s[M] &amp;&amp;                   //   if we haven't reached the maximum length:
      m[0][S]((_, x, a) =&gt;       //     try all 'down' moves:
        g(                       //       do a recursive call:
          s + 'D' + x,           //         append the move to s
          m.map(([...r], y) =&gt;   //         for each row r[] at position y:
            (r[x] =              //           rotate the column x by replacing r[x] with
              (m[y + 1] || a)[x] //           m[y + 1][x] or a[x] for the last row (a = m[0])
            ) &amp;&amp; r               //           yield the updated row
      ))) |                      //
      m[S]((_, y) =&gt;             //     try all 'right' moves:
        g(                       //       do a recursive call:
          s + 'R' + y,           //         append the move to s
          m.map(([...r]) =&gt;      //         for each row:
            y-- ?                //           if this is not the row we're looking for:
              r                  //             leave it unchanged
            :                    //           else:
              [r.pop(), ...r]    //             rotate it to the right
      )))                        //
    :                            // else (the matrix is sorted):
      o = s                      //   store the solution in o
)([], m) ?                       // initial call to g(); if we have a solution:
  o                              //   return it
:                                // else:
  f(m, M + 2)                    //   try again with a larger maximum length