Check to the king#6361

Check to the king

1 second
64 megabytes
Medium

From Misty Albion, our travelers journeyed to India, where they were mesmerized by the ancient temples' enchanting beauty. During their travels, they also developed an interest in the history of chess, often spending evenings solving chess puzzles and creating their own. One day, Mr. Kotsky presented his friends with the following challenge: On a chessboard, a white rook, a black king, and other pieces (K \geq 0) are placed randomly. What is the minimum number of moves (N \geq 0) required for the white rook to check the black king?

Input

-st line: The positions of the white rook and the black king on the chessboard.

-nd line: The positions of the other pieces on the chessboard.

Output

A single integer representing the minimum number of moves needed for the white rook to check the black king, or if it is impossible.

Examples

Example 1

Loading
Loading

Note

The rook can move any number of squares along a rank or file, as long as the path is unobstructed. The king is in check if the rook and king are on the same rank or file with no pieces between them. The chessboard ranks are numbered from to , and the files are labeled with the letters to .