h,w=[int(x) for x in input().rstrip().split()]
l=[list(input()) for i in range(h)]
dist=[[0]*w for i in range(h)]
move=[[1,0],[-1,0],[0,-1],[0,1]]
def bfs():
  stack=[[0,h-1]]
  done=[[False]*w for i in range(h)]
  done[h-1][0]=True
  while(stack):
    nx,ny=stack.pop(0)
    for dx,dy in move:
      mx=nx+dx
      my=ny+dy
      if not(0<=mx<=w-1) or not(0<=my<=h-1) or done[my][mx]==True or l[my][mx]=="#":
        continue
      done[my][mx]=True
      dist[my][mx]=dist[ny][nx]+1
      stack.append([mx,my])
bfs()
print(dist[0][w-1])