# import sys; input = sys.stdin.buffer.readline # sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) #処理内容 def main(): H, W = getlist() table = [] for i in range(H): l = list(input()) table.append(l) DP = [[INF] * W for i in range(H)] DP[0][0] = 0 for j in range(1, W): if table[0][j] == ".": DP[0][j] = DP[0][j - 1] + 1 else: DP[0][j] = DP[0][j - 1] + 1 + j for i in range(1, H): if table[i][0] == ".": DP[i][0] = DP[i - 1][0] + 1 else: DP[i][0] = DP[i - 1][0] + 1 + i # DP for i in range(1, H): for j in range(1, W): if table[i][j] == ".": DP[i][j] = min(DP[i - 1][j], DP[i][j - 1]) + 1 else: DP[i][j] = min(DP[i - 1][j], DP[i][j - 1]) + 1 + i + j ans = DP[-1][-1] print(ans) if __name__ == '__main__': main()