import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

h, w = rm()
s = [list(rr()) for _ in range(h)]
q = collections.deque([[0, 0]])
lidx = [1, 0, 0, 1]
lidy = [0, 1, -1, 0]
cnt = [[-1]*w for _ in range(h)]
cnt[0][0] = 0
while q:
    x, y = q.popleft()
    s[x][y] = '#'
    if x == h-1 and y == w-1:
        break
    for dx, dy in zip(lidx, lidy):
        if 0 <= x+dx < w and 0 <= y+dy < h and s[x+dx][y+dy] == '.':
            q.append([x+dx, y+dy])
            cnt[x+dx][y+dy] = cnt[x][y]+1
print(cnt[h-1][w-1])