import numpy as np



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

grid = np.array(['*'*(w+2)] + ['*'+eval(input())+'*' for _ in range(h)] + ['*'*(w+2)])



cnt = np.full((h+3, w+3), h+w, dtype=np.int)

MAX = h + w

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

    for k in range(1, w+2):

        if i == k == 1:

            cnt[i+1][k+1] = 1 if grid[i][k] == '#' else 0

        else:

            if grid[i][k] == '#':

                if grid[i-1][k] == '#':

                    a = cnt[i][k+1]

                elif grid[i-1][k] == '.':

                    a = cnt[i][k+1] + 1

                else:

                    a = MAX

                if grid[i][k-1] == '#':

                    b = cnt[i+1][k]

                elif grid[i][k-1] == '.':

                    b = cnt[i+1][k] + 1

                else:

                    b = MAX

                cnt[i+1][k+1] = min(a, b)

            else:

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



print((cnt[h+1][w+1]))

import numpy as np



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

grid = np.array([list(eval(input())) for _ in range(h)])



dp = np.full((h+1, w+1), h+w, dtype=np.int)



for i in range(h):

    for k in range(w):

        if i == k == 0:

            dp[i+1, k+1] = 1 if grid[i, k] == '#' else 0

        else:

            if grid[i, k] == '#':

                a = dp[i, k+1] if grid[i-1, k] == '#' else dp[i, k+1] + 1

                b = dp[i+1, k] if grid[i, k-1] == '#' else dp[i+1, k] + 1

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

            else:

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



print((dp[h, w]))

import numpy as np

h, w = list(map(int, input().split()))
grid = np.array(
    ["*" * (w + 2)] + ["*" + eval(input()) + "*" for _ in range(h)] + ["*" * (w + 2)]
)
cnt = np.full((h + 3, w + 3), h + w, dtype=np.int)
MAX = h + w
for i in range(1, h + 2):
    for k in range(1, w + 2):
        if i == k == 1:
            cnt[i + 1][k + 1] = 1 if grid[i][k] == "#" else 0
        else:
            if grid[i][k] == "#":
                if grid[i - 1][k] == "#":
                    a = cnt[i][k + 1]
                elif grid[i - 1][k] == ".":
                    a = cnt[i][k + 1] + 1
                else:
                    a = MAX
                if grid[i][k - 1] == "#":
                    b = cnt[i + 1][k]
                elif grid[i][k - 1] == ".":
                    b = cnt[i + 1][k] + 1
                else:
                    b = MAX
                cnt[i + 1][k + 1] = min(a, b)
            else:
                cnt[i + 1][k + 1] = min(cnt[i][k + 1], cnt[i + 1][k])
print((cnt[h + 1][w + 1]))

import numpy as np

h, w = list(map(int, input().split()))
grid = np.array([list(eval(input())) for _ in range(h)])
dp = np.full((h + 1, w + 1), h + w, dtype=np.int)
for i in range(h):
    for k in range(w):
        if i == k == 0:
            dp[i + 1, k + 1] = 1 if grid[i, k] == "#" else 0
        else:
            if grid[i, k] == "#":
                a = dp[i, k + 1] if grid[i - 1, k] == "#" else dp[i, k + 1] + 1
                b = dp[i + 1, k] if grid[i, k - 1] == "#" else dp[i + 1, k] + 1
                dp[i + 1, k + 1] = min(a, b)
            else:
                dp[i + 1, k + 1] = min(dp[i, k + 1], dp[i + 1, k])
print((dp[h, w]))

-grid = np.array( -    ["*" * (w + 2)] + ["*" + eval(input()) + "*" for _ in range(h)] + ["*" * (w + 2)] -) -cnt = np.full((h + 3, w + 3), h + w, dtype=np.int) -MAX = h + w -for i in range(1, h + 2): -    for k in range(1, w + 2): -        if i == k == 1: -            cnt[i + 1][k + 1] = 1 if grid[i][k] == "#" else 0 +grid = np.array([list(eval(input())) for _ in range(h)]) +dp = np.full((h + 1, w + 1), h + w, dtype=np.int) +for i in range(h): +    for k in range(w): +        if i == k == 0: +            dp[i + 1, k + 1] = 1 if grid[i, k] == "#" else 0 -            if grid[i][k] == "#": -                if grid[i - 1][k] == "#": -                    a = cnt[i][k + 1] -                elif grid[i - 1][k] == ".": -                    a = cnt[i][k + 1] + 1 -                else: -                    a = MAX -                if grid[i][k - 1] == "#": -                    b = cnt[i + 1][k] -                elif grid[i][k - 1] == ".": -                    b = cnt[i + 1][k] + 1 -                else: -                    b = MAX -                cnt[i + 1][k + 1] = min(a, b) +            if grid[i, k] == "#": +                a = dp[i, k + 1] if grid[i - 1, k] == "#" else dp[i, k + 1] + 1 +                b = dp[i + 1, k] if grid[i, k - 1] == "#" else dp[i + 1, k] + 1 +                dp[i + 1, k + 1] = min(a, b) -                cnt[i + 1][k + 1] = min(cnt[i][k + 1], cnt[i + 1][k]) -print((cnt[h + 1][w + 1])) +                dp[i + 1, k + 1] = min(dp[i, k + 1], dp[i + 1, k]) +print((dp[h, w]))