Cap
During a lesson, the top student, Petro Pyatochkin, devised a game to pass the time. He took a rectangular sheet from his notebook and colored some of its cells with a pen. Afterward, he removed the pen's cap and placed it on one of the colored cells. Petro then began moving the cap from one colored cell to another, ensuring each move was to a cell in the same row or column as the previous one. Petro has now selected a specific colored cell as his target and wants to move the cap there from its starting position in the fewest moves possible.
Your task is to write a program that, given the dimensions of the sheet, the layout of the colored cells, the initial position of the cap, and the target cell, determines the minimum number of moves required for Petro to reach the target cell according to his rules.
Input
The first line contains two integers: the number of rows N and the number of columns M of the sheet (2 ≤ M ≤ N ≤ 1000). Each of the following N lines contains M characters representing the cells:
x (lowercase Latin letter) - a colored cell.
. (dot) - an empty cell.
o (lowercase Latin letter) - the initial cell where the cap is placed.
+ (plus) - the target cell.
The input guarantees exactly one initial cell and one target cell.
Output
Output a single integer representing the minimum number of moves Petro needs to reach the target cell. If reaching the target cell is impossible under the given rules, output -1.