from sys import stdin N = int(stdin.readline()) used = [[0 for i in range(N)]for i in range(N)] #print(Ns) x = 1 y = 1 q = [[1, 1]] Ns = [] for i in range(N): Ns.append(stdin.readline().rstrip())
if Ns[N-2][N-2] == "#": print("No solution!") exit()
while q: a = q.pop(0) x = a[0] y = a[1] if x == N - 2 and y == N - 2 : #print("Yes") print(used[x][y] + 1) #第一步 exit() if x + 1 < N: if Ns[x+1][y] == "." and used[x+1][y] == 0: used[x+1][y] = used[x][y] + 1 q.append([x+1, y]) if x - 1 > 0: if Ns[x-1][y] == "." and used[x-1][y] == 0: used[x-1][y] = used[x][y] + 1 q.append([x-1, y]) if y + 1 < N: if Ns[x][y+1] == "." and used[x][y+1] == 0: used[x][y+1] = used[x][y] + 1 q.append([x, y+1]) if y - 1 > 0: if Ns[x][y-1] == "." and used[x][y-1] == 0: used[x][y-1] = used[x][y] + 1 q.append([x, y-1]) print("No solution!")