You are given a container represented as an $$$N \times M$$$ grid. Each cell in the grid contains a type of cargo, where the cargo in row $$$i$$$ and column $$$j$$$ is denoted by $$$a_{i, j}$$$. Rows are numbered from top to bottom $$$1, 2, \ldots, N$$$; columns from left to right $$$1, 2, \ldots, M$$$. Each row is equipped with a conveyor belt. When you activate the conveyor belt in row $$$i$$$, all the cargo in that row shifts one cell to the right, with the rightmost cargo wrapping around to the leftmost cell. For example, if the row initially contains $$$[1, 2, 3, 4]$$$, after one shift it becomes $$$[4, 1, 2, 3]$$$.
In addition, there is an empty cell located above the first cell of the first column (i.e., just above $$$a_{1, 1}$$$). You can move this empty cell by swapping it with the cargo directly above or below it, as long as such a cell exists. Specifically:
Your goal is to perform a sequence of operations to arrange the container into a "sorted" state. A container is considered sorted if it satisfies both of the following conditions:
Determine whether it's possible to reach the sorted state. If it is, output a sequence of operations to achieve it. Otherwise, state that it's impossible.
The first line of the input contains two integers $$$N$$$ and $$$M$$$, the number of rows and the number of columns.
Each of the next $$$N$$$ lines describes one row of the container. The $$$i$$$-th of these lines contains $$$M$$$ integers $$$a_{i, 1}, a_{i, 2}, \ldots, a_{i, M}$$$, the initial contents of row $$$i$$$.
If the goal is not achievable, output a single line containing $$$-1$$$.
Otherwise, on the first line outputs an integer $$$K$$$, the number of operations you need to perform.
On the second line outputs $$$K$$$ integers $$$b_1, b_2, \ldots, b_K$$$, where the $$$i$$$-th integer denotes the $$$i$$$-th operation:
Your answer will be considered correct if:
Note that you do not have to minimize the number of operations.
2 2 1 3 4 2
6 -2 1 -2 2 -1 -1
2 3 1 2 3 4 5 6
5 1 1 1 -2 -1
2 31 2 34 6 5
-1
3 3 1 2 3 9 4 6 5 7 8
13 -2 1 1 -2 2 -2 3 -1 2 -1 1 -1 3
Below picture shows how to perform a sequence of operations to make the first sample sorted. Here, we use $$$0$$$ to represent the empty cell.