def main(): import sys from collections import deque input = sys.stdin.readline H, W = map(int, input().split()) grid = [] for _ in range(H): line = input().rstrip('\n') grid.append(line) d = [(0, 1), (1, 0), (-1, 0), (0, -1)] inf = float('inf') que = deque() que.append((0, 0)) seen = [[inf] * W for _ in range(H)] seen[0][0] = 0 while que: h, w = que.popleft() for dh, dw in d: h_new, w_new = h+dh, w+dw if 0 <= h_new < H and 0 <= w_new < W: if seen[h_new][w_new] > 10**9: que.append((h_new, w_new)) if grid[h_new][w_new] == '.': seen[h_new][w_new] = min(seen[h_new][w_new], seen[h][w] + 1) else: seen[h_new][w_new] = min(seen[h_new][w_new], seen[h][w] + 1 + h_new + w_new) print(seen[-1][-1]) if __name__ == '__main__': main()