from math import ceil

from collections import defaultdict



h, w = list(map(int, input().split()))

s = [eval(input()) for _ in range(h)]



n = h * w

INF = 100 * 100



dp = defaultdict(lambda: INF)

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

    dp[(1, 1, 1)] = 1

else:

    dp[(1, 1, 0)] = 0



for i in range(1, h + 1):

    for j in range(1, w + 1):

        if s[i-1][j-1] == "#":

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

        else:

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



idx = 1 if s[h-1][w-1] == "#" else 0

ans = dp[(h, w, idx)]

ans = ceil(ans / 2)

print(ans)

def f(c):

    if c == "#":

        ret = 1

    else:

        ret = 0



    return ret





h, w = list(map(int, input().split()))

s = [list(map(f, "#" * (w + 1)))]

for _ in range(h):

    s.append([1] + list(map(f, eval(input()))))

INF = 100 * 100



dp = [[[INF] * 2 for _ in range(w + 1)] for _ in range(h + 1)]

dp[1][1][s[1][1]] = s[1][1]



for i, (row_u, row) in enumerate(zip(s, s[1:]), 1):

    for j, (el, eu, e) in enumerate(zip(row, row_u[1:], row[1:]), 1):

        dp[i][j][e] = min(dp[i][j][e], dp[i-1][j][eu] + (eu + e) % 2, dp[i][j-1][el] + (el + e) % 2)



ans = dp[h][w][s[h][w]]

ans = (ans + 1) // 2

print(ans)

from math import ceil
from collections import defaultdict

h, w = list(map(int, input().split()))
s = [eval(input()) for _ in range(h)]
n = h * w
INF = 100 * 100
dp = defaultdict(lambda: INF)
if s[0][0] == "#":
    dp[(1, 1, 1)] = 1
else:
    dp[(1, 1, 0)] = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i - 1][j - 1] == "#":
            dp[(i, j, 1)] = min(
                dp[(i, j, 1)],
                dp[(i - 1, j, 0)] + 1,
                dp[(i - 1, j, 1)],
                dp[(i, j - 1, 0)] + 1,
                dp[(i, j - 1, 1)],
            )
        else:
            dp[(i, j, 0)] = min(
                dp[(i, j, 0)],
                dp[(i - 1, j, 0)],
                dp[(i - 1, j, 1)] + 1,
                dp[(i, j - 1, 0)],
                dp[(i, j - 1, 1)] + 1,
            )
idx = 1 if s[h - 1][w - 1] == "#" else 0
ans = dp[(h, w, idx)]
ans = ceil(ans / 2)
print(ans)

def f(c):
    if c == "#":
        ret = 1
    else:
        ret = 0
    return ret


h, w = list(map(int, input().split()))
s = [list(map(f, "#" * (w + 1)))]
for _ in range(h):
    s.append([1] + list(map(f, eval(input()))))
INF = 100 * 100
dp = [[[INF] * 2 for _ in range(w + 1)] for _ in range(h + 1)]
dp[1][1][s[1][1]] = s[1][1]
for i, (row_u, row) in enumerate(zip(s, s[1:]), 1):
    for j, (el, eu, e) in enumerate(zip(row, row_u[1:], row[1:]), 1):
        dp[i][j][e] = min(
            dp[i][j][e],
            dp[i - 1][j][eu] + (eu + e) % 2,
            dp[i][j - 1][el] + (el + e) % 2,
        )
ans = dp[h][w][s[h][w]]
ans = (ans + 1) // 2
print(ans)

-from math import ceil -from collections import defaultdict +def f(c): +    if c == "#": +        ret = 1 +    else: +        ret = 0 +    return ret + -s = [eval(input()) for _ in range(h)] -n = h * w +s = [list(map(f, "#" * (w + 1)))] +for _ in range(h): +    s.append([1] + list(map(f, eval(input())))) -dp = defaultdict(lambda: INF) -if s[0][0] == "#": -    dp[(1, 1, 1)] = 1 -else: -    dp[(1, 1, 0)] = 0 -for i in range(1, h + 1): -    for j in range(1, w + 1): -        if s[i - 1][j - 1] == "#": -            dp[(i, j, 1)] = min( -                dp[(i, j, 1)], -                dp[(i - 1, j, 0)] + 1, -                dp[(i - 1, j, 1)], -                dp[(i, j - 1, 0)] + 1, -                dp[(i, j - 1, 1)], -            ) -        else: -            dp[(i, j, 0)] = min( -                dp[(i, j, 0)], -                dp[(i - 1, j, 0)], -                dp[(i - 1, j, 1)] + 1, -                dp[(i, j - 1, 0)], -                dp[(i, j - 1, 1)] + 1, -            ) -idx = 1 if s[h - 1][w - 1] == "#" else 0 -ans = dp[(h, w, idx)] -ans = ceil(ans / 2) +dp = [[[INF] * 2 for _ in range(w + 1)] for _ in range(h + 1)] +dp[1][1][s[1][1]] = s[1][1] +for i, (row_u, row) in enumerate(zip(s, s[1:]), 1): +    for j, (el, eu, e) in enumerate(zip(row, row_u[1:], row[1:]), 1): +        dp[i][j][e] = min( +            dp[i][j][e], +            dp[i - 1][j][eu] + (eu + e) % 2, +            dp[i][j - 1][el] + (el + e) % 2, +        ) +ans = dp[h][w][s[h][w]] +ans = (ans + 1) // 2