Chess from "Harry Potter"
A lot of people were impressed with the huge chess scene in a movie about Harry Potter. It showed that the chess can also be danger for life. The fact is that there are figures being killed for real, but only under the rules of chess, of course.
Figures have a lot of free time. They are boring to just stand and wait until someone dares to play with them. Therefore, from time to time, they play with themselves. But there was a little problem. Every time one of the figures being killed crushing blow of the sword, it shatters into pieces and remains on the board. This prevents the rest of the figures move. Therefore, they are forced to ask a fairy with a magic vacuum cleaner (which is also, frankly, have nothing to do) to help them and remove the remains of figures, retired from the game. The vacuum cleaner is quite voluminous, though the magic. He can only move through empty cells with common sides. To make "cleaning" as fast as possible, the fairy asks you to determine the minimum number of squares of the chessboard, which she needed to go through to be in a cage with a dead figure. Initially, the fairy is outside the board.
Input The first line contains the number of pieces (2 ≤ n ≤ 31), are currently on the board, and the coordinates of the cell in which the murder occurred. The following n lines indicate the coordinates of the figures, the first of which contains a hierarchy (from a to h), and the second horizontal line (from 1 to 8).
Output
Print the minimum number of cells, including cell with killed figure, which is necessary to pass the fairy. If it is impossible, then output "-1" (without the quotes).