Check to the king
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 K other pieces (K ≥ 0) are placed randomly. What is the minimum number of moves N (N ≥ 0) required for the white rook to check the black king?
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 1 to 8, and the files are labeled with the letters A to H.
Input
1-st line: The positions of the white rook and the black king on the chessboard.
2-nd line: The positions of the other pieces on the chessboard.
Output
A single integer representing the minimum number of moves N needed for the white rook to check the black king, or -1 if it is impossible.