from collections import deque
H, W = map(int, input().split())

route = []
for _ in range(H):
  route.append(input())
  
dp = [[0 for _ in range(W)] for __ in range(H)]

already = set()
already.add((0,0))
for y, r in enumerate(route):
  for x, w in enumerate(r):
    if w == '#':
      already.add((x, H-y-1))

d = deque()
d.append((0,0,0))
while len(d) > 0:
  now = d.popleft()
  if now[:-1] == (W-1, H-1):
    print(now[-1])
    break
  step = now[2]+1
  x,y = now[0]-1, now[1]
  if (x, y) not in already and x >= 0:
    d.append((x, y, step))
  x, y = x+1, y-1
  if (x, y) not in already and y >= 0:
    d.append((x, y, step))
  x, y = x+1, y+1
  if (x, y) not in already and x < W:
    d.append((x, y, step))
  x, y = x-1, y+1
  if (x, y) not in already and y < H:
    d.append((x, y, step))
    
