Jerry developed a new board game recently. The board consists of N*N grids and M pieces have been randomly put in these grids. The game rules are defined as follows.
1. There is a unique grid defined as exit-grid.
2. In the initial state, no pieces is in exit-grid, and all the pieces are not adjacent to each other(in four directions: up, down, left, right).
3. All the M pieces are marked from 1 to M .
4. Each time you are allowed to move one piece to one of its adjacent blocks, which is counted as one step.
5. When you move the pieces, make sure that all the pieces are not adjacent to each other.
6. When the smallest piece, i.e. its marked number is the smallest on the board, is moved to exit-grid, you can take that piece away from the board. Pieces other than the smallest one are also allowed to move to exit-grid but they cannot be taken away.
7. When all the pieces on the board have been taken away, you win the game.
Tom is a very evil person. Every time Jerry playing the board game, he always says he has a better way to win the game, but he is not willing to tell Jerry. Jerry does not know whether Tom's words are true or not, so he asks for your help to write a program that can count the number of fewest steps to win the board game.