const
dx:array[1..4]of longint=(1,-1,0,0);
dy:array[1..4]of longint=(0,0,-1,1);
type
node=record
x,y:longint;
bo:boolean;
step:longint;
end;
re=record
bo:longint;
n:longint;
end;
var
n,m:longint;
map:array[1..1000,1..1000]of char;
step:array[1..1000,1..1000]of longint;
time:array[1..1000,1..1000]of re;
f:array[0..1001,0..1001]of boolean;
h:array[1..1000000]of node;
flag:boolean;
ans:longint;
procedure init;
begin
assign(input,'ty1143.in');
assign(output,'ty1143.out');
reset(input); rewrite(output);
end;
procedure terminate;
begin
close(input); close(output);
halt;
end;
procedure bfs;
var
i:longint;
l,r:longint;
x,y:longint;
begin
flag:=false;
ans:=maxlongint;
l:=0; r:=1;
fillchar(step,sizeof(step),$7);
h[1].x:=1; h[1].y:=1;
h[1].step:=0;
h[1].bo:=true;
repeat
inc(l);
if l=1000000 then l:=1;
for i:=1 to 4 do
begin
x:=h[l].x+dx[i];
y:=h[l].y+dy[i];
if f[x,y] then
begin
if (map[x,y]='.') then
begin
if h[l].bo then
begin
if time[x,y].n>h[l].step+1 then
begin
time[x,y].n:=h[l].step+1;
inc(r);
if r=1000000 then r:=1;
h[r].step:=h[l].step+1;
h[r].bo:=h[l].bo;
h[r].x:=x;
h[r].y:=y;
end;
end;
if not h[l].bo then
begin
if time[x,y].bo>h[l].step+1 then
begin
time[x,y].bo:=h[l].step+1;
inc(r);
if r=1000000 then r:=1;
h[r].step:=h[l].step+1;
h[r].bo:=h[l].bo;
h[r].x:=x;
h[r].y:=y;
end;
end;
end
else
if (map[x,y]='*')and(h[l].bo)then
begin
if time[x,y].bo>h[l].step+1 then
begin
time[x,y].bo:=h[l].step+1;
inc(r);
if r=1000000 then r:=1;
h[r].step:=h[l].step+1;
h[r].bo:=false;
h[r].x:=x;
h[r].y:=y;
end;
end;
end;
if (h[r].x=n) and (h[r].y=m) then
begin
if ans>h[r].step then
begin
ans:=h[r].step;
flag:=true;
end;
end;
end;
until l>=r;
if flag then writeln(ans)
else writeln('no');
end;
procedure main;
var
i,j:longint;
begin
readln(n,m);
fillchar(f,sizeof(f),false);
for i:=1 to n do
begin
for j:=1 to m do
begin
read(map[i,j]);
f[i,j]:=true;
time[i,j].bo:=maxlongint;
time[i,j].n:=maxlongint;
end;
readln;
end;
bfs;
end;
begin
init;
main;
terminate;
end.