import sys

import numpy as np

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

I = np.array([list(map(str, eval(input()))) for _ in range(H)])

grid = np.zeros([H,W], np.int16)

grid[np.where(I=='#')] = 1

inf = np.inf

dp = np.full([H,W], inf)

if grid[0,0] == 1:

    dp[0,0] = 1

else:

    dp[0,0] = 0



for i in range(H):

    for j in range(W):

        if i + 1 < H:

            if grid[i,j] == grid[i+1,j]:

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

            else:

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

        if j + 1 < W:

            if grid[i,j] == grid[i,j+1]:

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

            else:

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

if grid[-1,-1] == 1:

    dp[-1,-1,] += 1

ans = dp[-1,-1]//2

print((int(ans)))

import numpy as np

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

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



I = [list(map(str, eval(input()))) for _ in range(H)]



dp = [[0] * W for _ in range(H)]



for i in range(H):

	for j in range(W):

		if i == 0 and j == 0:

			continue

		if i == 0:

			dp[i][j] = dp[i][j-1] if I[i][j] == I[i][j-1] else dp[i][j-1] + 1

			continue

		if j == 0:

			dp[i][j] = dp[i-1][j] if I[i][j] == I[i-1][j] else dp[i-1][j] + 1

			continue



		dp[i][j] = dp[i][j-1] if I[i][j] == I[i][j-1] else dp[i][j-1] + 1

		if I[i][j] == I[i-1][j]:

			dp[i][j] = min(dp[i][j], dp[i-1][j])

		else:

			dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)	



t = dp[-1][-1]

if I[0][0] == "#":

	t += 1

ans = -(-t//2)



print(ans)

		

import sys
import numpy as np

H, W = list(map(int, input().split()))
I = np.array([list(map(str, eval(input()))) for _ in range(H)])
grid = np.zeros([H, W], np.int16)
grid[np.where(I == "#")] = 1
inf = np.inf
dp = np.full([H, W], inf)
if grid[0, 0] == 1:
    dp[0, 0] = 1
else:
    dp[0, 0] = 0
for i in range(H):
    for j in range(W):
        if i + 1 < H:
            if grid[i, j] == grid[i + 1, j]:
                dp[i + 1, j] = min(dp[i + 1, j], dp[i, j])
            else:
                dp[i + 1, j] = min(dp[i + 1, j], dp[i, j] + 1)
        if j + 1 < W:
            if grid[i, j] == grid[i, j + 1]:
                dp[i, j + 1] = min(dp[i, j + 1], dp[i, j])
            else:
                dp[i, j + 1] = min(dp[i, j + 1], dp[i, j] + 1)
if grid[-1, -1] == 1:
    dp[
        -1,
        -1,
    ] += 1
ans = dp[-1, -1] // 2
print((int(ans)))

import numpy as np
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
H, W = list(map(int, input().split()))
I = [list(map(str, eval(input()))) for _ in range(H)]
dp = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:
            continue
        if i == 0:
            dp[i][j] = dp[i][j - 1] if I[i][j] == I[i][j - 1] else dp[i][j - 1] + 1
            continue
        if j == 0:
            dp[i][j] = dp[i - 1][j] if I[i][j] == I[i - 1][j] else dp[i - 1][j] + 1
            continue
        dp[i][j] = dp[i][j - 1] if I[i][j] == I[i][j - 1] else dp[i][j - 1] + 1
        if I[i][j] == I[i - 1][j]:
            dp[i][j] = min(dp[i][j], dp[i - 1][j])
        else:
            dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1)
t = dp[-1][-1]
if I[0][0] == "#":
    t += 1
ans = -(-t // 2)
print(ans)

+import numpy as np -import numpy as np +read = sys.stdin.read +readline = sys.stdin.readline +readlines = sys.stdin.readlines -I = np.array([list(map(str, eval(input()))) for _ in range(H)]) -grid = np.zeros([H, W], np.int16) -grid[np.where(I == "#")] = 1 -inf = np.inf -dp = np.full([H, W], inf) -if grid[0, 0] == 1: -    dp[0, 0] = 1 -else: -    dp[0, 0] = 0 +I = [list(map(str, eval(input()))) for _ in range(H)] +dp = [[0] * W for _ in range(H)] -        if i + 1 < H: -            if grid[i, j] == grid[i + 1, j]: -                dp[i + 1, j] = min(dp[i + 1, j], dp[i, j]) -            else: -                dp[i + 1, j] = min(dp[i + 1, j], dp[i, j] + 1) -        if j + 1 < W: -            if grid[i, j] == grid[i, j + 1]: -                dp[i, j + 1] = min(dp[i, j + 1], dp[i, j]) -            else: -                dp[i, j + 1] = min(dp[i, j + 1], dp[i, j] + 1) -if grid[-1, -1] == 1: -    dp[ -        -1, -        -1, -    ] += 1 -ans = dp[-1, -1] // 2 -print((int(ans))) +        if i == 0 and j == 0: +            continue +        if i == 0: +            dp[i][j] = dp[i][j - 1] if I[i][j] == I[i][j - 1] else dp[i][j - 1] + 1 +            continue +        if j == 0: +            dp[i][j] = dp[i - 1][j] if I[i][j] == I[i - 1][j] else dp[i - 1][j] + 1 +            continue +        dp[i][j] = dp[i][j - 1] if I[i][j] == I[i][j - 1] else dp[i][j - 1] + 1 +        if I[i][j] == I[i - 1][j]: +            dp[i][j] = min(dp[i][j], dp[i - 1][j]) +        else: +            dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1) +t = dp[-1][-1] +if I[0][0] == "#": +    t += 1 +ans = -(-t // 2) +print(ans)