H, W = map(int, input().split())
S = [list("#"+input()) for _ in range(H)] + [["#"]*(H+1)]
#print(S)

seen = [[False for _ in range(W+1)] for _ in range(H+1)]
seen[H-1][1]=True
#print(seen)

D = [-1, 1]
stack = [[H-1, 1]]
i = -1

while stack:
    now = stack.pop()
    h = now[0]
    w = now[1]
    if h == 0 and w == W-1:
        break
    #print(S[h][0][w])
    for d in D:
        try:
            if seen[h-d][w] ==True:
                pass
            elif S[h-d][w] == ".":
                stack.append([h-d, w])
                seen[h-d][w] = True
        except:
            pass
        try:
            if seen[h][w+d] ==True:
                pass
            elif S[h][w+d] == ".":
                stack.append([h, w+d])
                seen[h][w+d] = True
        except:
            pass
    #print(seen)
    i += 1

#print(seen)
print(i)