var i,j,n,m,x,y,tot:integer;
a:array[1..1000,1..1000] of char;
que:array[1..1000,1..2] of integer;
v:array[1..1000,1..1000] of boolean;
xx:array[1..4] of integer = (0,1,0,-1);
yy:array[1..4] of integer = (1,0,-1,0);
procedure bfs;
var head,tail,tl:integer;
f:boolean;
begin
f:=true;
que[1,1]:=1; que[1,2]:=1;
head:=1; tail:=1;tl:=1;
while (head<=tail)and f do
begin
inc(tot);
for j:=head to tail do
for i:=1 to 4 do
begin
x:=que[j,1]+xx[i];
y:=que[j,2]+yy[i];
if (x>0) and (x<=n) and (y>0) and (y<=n) and (v[x,y])and f then
begin
if (x=n)and(y=n) then f:=false;
inc(tl);
que[tl,1]:=x;
que[tl,2]:=y;
v[x,y]:=false;
end;
end;
tail:=tl;
inc(head);
end;
writeln(tot);
end;
begin
readln(n);
fillchar(v,sizeof(v),false);
x:=1;
y:=1;
for i:=1 to n do
begin
for j:=1 to n do
begin
read(a[i,j]);
if a[i,j]='.' then v[i,j]:=true;
end;
readln;
end;
bfs;
end.
a:array[1..1000,1..1000] of char;
que:array[1..1000,1..2] of integer;
v:array[1..1000,1..1000] of boolean;
xx:array[1..4] of integer = (0,1,0,-1);
yy:array[1..4] of integer = (1,0,-1,0);
procedure bfs;
var head,tail,tl:integer;
f:boolean;
begin
f:=true;
que[1,1]:=1; que[1,2]:=1;
head:=1; tail:=1;tl:=1;
while (head<=tail)and f do
begin
inc(tot);
for j:=head to tail do
for i:=1 to 4 do
begin
x:=que[j,1]+xx[i];
y:=que[j,2]+yy[i];
if (x>0) and (x<=n) and (y>0) and (y<=n) and (v[x,y])and f then
begin
if (x=n)and(y=n) then f:=false;
inc(tl);
que[tl,1]:=x;
que[tl,2]:=y;
v[x,y]:=false;
end;
end;
tail:=tl;
inc(head);
end;
writeln(tot);
end;
begin
readln(n);
fillchar(v,sizeof(v),false);
x:=1;
y:=1;
for i:=1 to n do
begin
for j:=1 to n do
begin
read(a[i,j]);
if a[i,j]='.' then v[i,j]:=true;
end;
readln;
end;
bfs;
end.