H, W = list(map(int, input().split()))

grid = [eval(input()) for _ in range(H)]

dp = [[float('inf')] * W for i in range(H)]

dp[0][0] = 1 if grid[0][0] == '#' else 0



for i in range(H):

    for j in range(W):

        for y, x in ((1,0), (0,1)):

            ni, nj = i + y, j + x

            if ni >= H or nj >= W:

                continue

            c = 0

            if grid[ni][nj] == '#' and grid[i][j] == '.':

                c = 1

            dp[ni][nj] = min(dp[ni][nj], dp[i][j] + c)



print((dp[H-1][W-1]))
H, W = list(map(int,input().split()))

grid = [eval(input()) for _ in range(H)]

dp = [[float('inf')]*(W) for _ in range(H)]

dp[0][0] = 0 if grid[0][0] == '.' else 1

for i in range(H):

    for k in range(W):

        if i+1 < H:

            if grid[i][k] == '.' and grid[i+1][k] == '#':

                dp[i+1][k] = min(dp[i][k]+1,dp[i+1][k])

            else:

                dp[i+1][k] = min(dp[i][k],dp[i+1][k])

        if k+1 < W:

            if grid[i][k] == '.' and grid[i][k+1] == '#':

                dp[i][k+1] = min(dp[i][k]+1,dp[i][k+1])

            else:

                dp[i][k+1] = min(dp[i][k],dp[i][k+1])

print((dp[-1][-1]))
H, W = list(map(int, input().split()))
grid = [eval(input()) for _ in range(H)]
dp = [[float("inf")] * W for i in range(H)]
dp[0][0] = 1 if grid[0][0] == "#" else 0
for i in range(H):
    for j in range(W):
        for y, x in ((1, 0), (0, 1)):
            ni, nj = i + y, j + x
            if ni >= H or nj >= W:
                continue
            c = 0
            if grid[ni][nj] == "#" and grid[i][j] == ".":
                c = 1
            dp[ni][nj] = min(dp[ni][nj], dp[i][j] + c)
print((dp[H - 1][W - 1]))

H, W = list(map(int, input().split()))
grid = [eval(input()) for _ in range(H)]
dp = [[float("inf")] * (W) for _ in range(H)]
dp[0][0] = 0 if grid[0][0] == "." else 1
for i in range(H):
    for k in range(W):
        if i + 1 < H:
            if grid[i][k] == "." and grid[i + 1][k] == "#":
                dp[i + 1][k] = min(dp[i][k] + 1, dp[i + 1][k])
            else:
                dp[i + 1][k] = min(dp[i][k], dp[i + 1][k])
        if k + 1 < W:
            if grid[i][k] == "." and grid[i][k + 1] == "#":
                dp[i][k + 1] = min(dp[i][k] + 1, dp[i][k + 1])
            else:
                dp[i][k + 1] = min(dp[i][k], dp[i][k + 1])
print((dp[-1][-1]))

-dp = [[float("inf")] * W for i in range(H)] -dp[0][0] = 1 if grid[0][0] == "#" else 0 +dp = [[float("inf")] * (W) for _ in range(H)] +dp[0][0] = 0 if grid[0][0] == "." else 1 -    for j in range(W): -        for y, x in ((1, 0), (0, 1)): -            ni, nj = i + y, j + x -            if ni >= H or nj >= W: -                continue -            c = 0 -            if grid[ni][nj] == "#" and grid[i][j] == ".": -                c = 1 -            dp[ni][nj] = min(dp[ni][nj], dp[i][j] + c) -print((dp[H - 1][W - 1])) +    for k in range(W): +        if i + 1 < H: +            if grid[i][k] == "." and grid[i + 1][k] == "#": +                dp[i + 1][k] = min(dp[i][k] + 1, dp[i + 1][k]) +            else: +                dp[i + 1][k] = min(dp[i][k], dp[i + 1][k]) +        if k + 1 < W: +            if grid[i][k] == "." and grid[i][k + 1] == "#": +                dp[i][k + 1] = min(dp[i][k] + 1, dp[i][k + 1]) +            else: +                dp[i][k + 1] = min(dp[i][k], dp[i][k + 1]) +print((dp[-1][-1]))