From a checkered field of $$$n$$$ rows and $$$m$$$ columns ($$$5 \leq n, m \leq 1000$$$), the inner part of size $$$(n-4) \times (m-4)$$$ was cut out so that on the sides of it there remained strips of $$$2$$$ cells in width.
There is a chess knight on the top left square of the field. Is it possible, using only narrow strips of $$$2$$$ cells width, to go around the cutout with the knight, and return to the original (initial) cell? And if it is possible, what is the minimum number of moves required for this (the knight follows the chess rules)?
For example, if there is a field $$$5 \times5$$$ (the square $$$(3, 3)$$$ is cut out), then the knight can go around the cut in $$$4$$$ moves: $$$(1, 1) \rightarrow (3, 2) \rightarrow (4, 4) \rightarrow (2, 3) \rightarrow (1, 1)$$$.
Note. At the moment of movement, the knight cannot jump over the cut cells.
The size of the field is given as two integers $$$n$$$ and $$$m$$$ ($$$5 \leq n, m \leq 1000$$$), separated by a space.
Output $$$0$$$ if it is impossible to walk around the cutout, or the required number of the knight's moves for such a walk is minimal.
5 5
4
20 15
30
1000 1000
1996
5 6
6