// 迷宮問題1 //
// start from (1, 1).
// try to travel four directions,
// if there is a passage, then record now positon and go to next position.
// record lenth, when arrive at endpoint, compare it with minLenth.
#include <stdio.h>
char maze[100][100], trail[10000][2];
int n, minLen, destX, destY, visited[100][100] = {0};
void ShowNowPos(int x, int y)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (i == x && j == y)
printf("@ ");
else
printf("%c ", maze[i][j]);
}
printf("\n");
}
printf("\n");
}
void DFS(int nowX, int nowY, int len)
{
if (maze[nowX][nowY] == '#' || visited[nowX][nowY] == 1)
return;
// ShowNowPos(nowX, nowY);
if (nowX == destX && nowY == destY)
{
if (len < minLen)
minLen = len;
return;
}
// maze[nowX][nowY] = 'v';
visited[nowX][nowY] = 1;
BFS(nowX + 1, nowY, len + 1); // down
BFS(nowX, nowY + 1, len + 1); // right
BFS(nowX - 1, nowY, len + 1); // up
BFS(nowX, nowY - 1, len + 1); // left
// maze[nowX][nowY] = '.';
visited[nowX][nowY] = 0;
}
int main()
{
scanf("%d", &n);
destX = n - 2;
destY = n - 2;
minLen = n * n;
for (int i = 0; i < n; i++)
{
scanf("%s", maze[i]);
}
BFS(1, 1, 1);
if (minLen == n * n)
printf("No solution!");
else
printf("%d", minLen);
return 0;
}