Stampede!#6651

Stampede!

1 second
64 megabytes
Very hard

You have an n \times n game board. Some squares contain obstacles, except the left- and right-most columns which are obstacle-free. The left-most column is filled with your pieces, per row. Your goal is to move all your pieces to the right-most column as quickly as possible. In a given turn, you can move each piece N, S, E, or W one space, or leave that piece in place. A piece cannot move onto a square containing an obstacle, nor may two pieces move to the same square on the same turn. All pieces move simultaneously, so one may move to a location currently occupied by another piece so long as that piece itself moves elsewhere at the same time.

Given and the obstacles, determine the fewest number of turns needed to get all your pieces to the right-hand side of the board.

Input

Each test case starts with a positive integer indicating the size of the game board, with n \le 25. Following this will be lines containing characters each. If the -th character in the -th line is an 'X', then there is an obstacle in board location , ; otherwise this character will be a '.' indicating no obstacle.

There will never be an obstacle in the -th or (n-1)-th column and there will always be at least one obstacle-free path between these two columns. A line containing a single will terminate input.

Output

For each test case output the minimum number of turns to move all the pieces from the left side of the board to the right side.

Examples

Example 1

Loading
Loading