import sys

import collections



sys.setrecursionlimit(10 ** 8)



input = sys.stdin.readline





def main():

    H, W = [int(x) for x in input().split()]

    S = [list(input().strip()) for _ in range(H)]



    ans = 0

    f = False

    if S[0][0] == '#':

        ans += 1

        f = True



    q = collections.deque()

    q.append([[0, 0], 0, f])



    d = [[10 ** 9] * W for j in range(H)]



    while q:

        c = q.pop()

        dist = c[1]

        fl = c[2]



        j = c[0][0]

        i = c[0][1]



        if d[j][i] <= dist:

            continue

        else:

            d[j][i] = dist



        if i != W - 1:

            if S[j][i + 1] == '#':

                if fl:

                    q.append([[j, i + 1], dist, True])

                else:

                    q.append([[j, i + 1], dist + 1, True])

            else:

                q.append([[j, i + 1], dist, False])



        if j != H - 1:

            if S[j + 1][i] == '#':

                if fl:

                    q.append([[j + 1, i], dist, True])

                else:

                    q.append([[j + 1, i], dist + 1, True])

            else:

                q.append([[j + 1, i], dist, False])



    ans += d[H - 1][W - 1]



    print(ans)



if __name__ == '__main__':

        main()

import sys

import collections



sys.setrecursionlimit(10 ** 8)



input = sys.stdin.readline





def main():

    H, W = [int(x) for x in input().split()]

    S = [list(input().strip()) for _ in range(H)]



    dp = [[10 ** 9] * W for j in range(H)]



    if S[0][0] == '#':

        dp[0][0] = 1

    else:

        dp[0][0] = 0



    for j in range(H):

        for i in range(W):

            if j != H - 1:

                x = 1 if S[j + 1][i] == '#' and S[j][i] == '.' else 0

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

            if i != W - 1:

                x = 1 if S[j][i + 1] == '#' and S[j][i] == '.' else 0

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



    print((dp[-1][-1]))





if __name__ == '__main__':

    main()

import sys
import collections

sys.setrecursionlimit(10**8)
input = sys.stdin.readline


def main():
    H, W = [int(x) for x in input().split()]
    S = [list(input().strip()) for _ in range(H)]
    ans = 0
    f = False
    if S[0][0] == "#":
        ans += 1
        f = True
    q = collections.deque()
    q.append([[0, 0], 0, f])
    d = [[10**9] * W for j in range(H)]
    while q:
        c = q.pop()
        dist = c[1]
        fl = c[2]
        j = c[0][0]
        i = c[0][1]
        if d[j][i] <= dist:
            continue
        else:
            d[j][i] = dist
        if i != W - 1:
            if S[j][i + 1] == "#":
                if fl:
                    q.append([[j, i + 1], dist, True])
                else:
                    q.append([[j, i + 1], dist + 1, True])
            else:
                q.append([[j, i + 1], dist, False])
        if j != H - 1:
            if S[j + 1][i] == "#":
                if fl:
                    q.append([[j + 1, i], dist, True])
                else:
                    q.append([[j + 1, i], dist + 1, True])
            else:
                q.append([[j + 1, i], dist, False])
    ans += d[H - 1][W - 1]
    print(ans)


if __name__ == "__main__":
    main()

import sys
import collections

sys.setrecursionlimit(10**8)
input = sys.stdin.readline


def main():
    H, W = [int(x) for x in input().split()]
    S = [list(input().strip()) for _ in range(H)]
    dp = [[10**9] * W for j in range(H)]
    if S[0][0] == "#":
        dp[0][0] = 1
    else:
        dp[0][0] = 0
    for j in range(H):
        for i in range(W):
            if j != H - 1:
                x = 1 if S[j + 1][i] == "#" and S[j][i] == "." else 0
                dp[j + 1][i] = min(dp[j + 1][i], dp[j][i] + x)
            if i != W - 1:
                x = 1 if S[j][i + 1] == "#" and S[j][i] == "." else 0
                dp[j][i + 1] = min(dp[j][i + 1], dp[j][i] + x)
    print((dp[-1][-1]))


if __name__ == "__main__":
    main()

-    ans = 0 -    f = False +    dp = [[10**9] * W for j in range(H)] -        ans += 1 -        f = True -    q = collections.deque() -    q.append([[0, 0], 0, f]) -    d = [[10**9] * W for j in range(H)] -    while q: -        c = q.pop() -        dist = c[1] -        fl = c[2] -        j = c[0][0] -        i = c[0][1] -        if d[j][i] <= dist: -            continue -        else: -            d[j][i] = dist -        if i != W - 1: -            if S[j][i + 1] == "#": -                if fl: -                    q.append([[j, i + 1], dist, True]) -                else: -                    q.append([[j, i + 1], dist + 1, True]) -            else: -                q.append([[j, i + 1], dist, False]) -        if j != H - 1: -            if S[j + 1][i] == "#": -                if fl: -                    q.append([[j + 1, i], dist, True]) -                else: -                    q.append([[j + 1, i], dist + 1, True]) -            else: -                q.append([[j + 1, i], dist, False]) -    ans += d[H - 1][W - 1] -    print(ans) +        dp[0][0] = 1 +    else: +        dp[0][0] = 0 +    for j in range(H): +        for i in range(W): +            if j != H - 1: +                x = 1 if S[j + 1][i] == "#" and S[j][i] == "." else 0 +                dp[j + 1][i] = min(dp[j + 1][i], dp[j][i] + x) +            if i != W - 1: +                x = 1 if S[j][i + 1] == "#" and S[j][i] == "." else 0 +                dp[j][i + 1] = min(dp[j][i + 1], dp[j][i] + x) +    print((dp[-1][-1]))