H, W = map(int, input().split()) S = [input() for _ in range(H)] L = [(0,0)] Seen = [[False] * W for _ in range(H)] add_one_possible = False add_zero_possible = False dx = [1, 0] dy = [0, 1] while len(L): (x, y) = L.pop() if(x == H - 1 and y == W - 1): add_zero_possible = True break if(x >= H - 2 or y >= W - 2): add_one_possible = True for k in range(2): x2 = x + dx[k] y2 = y + dy[k] if(x2 < H and y2 < W and S[x2][y2] != "#" and not Seen[x2][y2]): Seen[x2][y2] = True L.append((x2, y2)) if(add_zero_possible): print(H + W - 2) elif(add_one_possible): print(H + W - 1) else: print(H + W)