import sys

from collections import deque



sys.setrecursionlimit(10 ** 7)

f_inf = float('inf')

mod = 10 ** 9 + 7





def resolve():

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

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



    # 白と黒が入れ替わった箇所をカウントする

    flip = [[f_inf for _ in range(W)] for _ in range(H)]



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

        flip[0][0] = 1

    else:

        flip[0][0] = 0



    que = deque([[0, 0]])

    while que:

        h, w = que.popleft()

        for dh, dw in ((0, 1), (1, 0)):

            next_h, next_w = h + dh, w + dw

            if next_h >= H or next_w >= W:

                continue



            if flip[next_h][next_w] == f_inf:

                que.append([next_h, next_w])



            # 白と黒が入れ替わったらカウントアップ

            if S[h][w] != S[next_h][next_w]:

                flip[next_h][next_w] = min(flip[next_h][next_w], flip[h][w] + 1)

            else:

                flip[next_h][next_w] = min(flip[next_h][next_w], flip[h][w])



    if S[H - 1][W - 1] == "#":

        flip[H - 1][W - 1] += 1



    # 操作の回数は白と黒が入れ替わった回数の半分（切り捨て）である

    print((flip[H - 1][W - 1] // 2))





if __name__ == '__main__':

    resolve()

import sys



sys.setrecursionlimit(10 ** 7)

f_inf = float('inf')

mod = 10 ** 9 + 7





def resolve():

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

    grid = [list("." + eval(input())) for _ in range(H)]



    dp = [[f_inf] * (W + 1) for _ in range(H)]

    dp[0][0] = 0



    for h in range(H):

        for w in range(W + 1):

            if w == 0:

                if h != 0:

                    continue

                next_h, next_w = h, w + 1

                if grid[h][w] == "." and grid[next_h][next_w] == "#":

                    dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)

                elif grid[h][w] == "." and grid[next_h][next_w] == "#":

                    dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)

                else:

                    dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w])

            else:

                for dh, dw in [(1, 0), (0, 1)]:

                    next_h, next_w = h + dh, w + dw

                    if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W + 1:

                        continue

                    if grid[h][w] == "." and grid[next_h][next_w] == "#":

                        dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)

                    elif grid[h][w] == "." and grid[next_h][next_w] == "#":

                        dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)

                    else:

                        dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w])

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





if __name__ == '__main__':

    resolve()

import sys
from collections import deque

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    H, W = list(map(int, input().split()))
    S = [list(eval(input())) for _ in range(H)]
    # 白と黒が入れ替わった箇所をカウントする
    flip = [[f_inf for _ in range(W)] for _ in range(H)]
    if S[0][0] == "#":
        flip[0][0] = 1
    else:
        flip[0][0] = 0
    que = deque([[0, 0]])
    while que:
        h, w = que.popleft()
        for dh, dw in ((0, 1), (1, 0)):
            next_h, next_w = h + dh, w + dw
            if next_h >= H or next_w >= W:
                continue
            if flip[next_h][next_w] == f_inf:
                que.append([next_h, next_w])
            # 白と黒が入れ替わったらカウントアップ
            if S[h][w] != S[next_h][next_w]:
                flip[next_h][next_w] = min(flip[next_h][next_w], flip[h][w] + 1)
            else:
                flip[next_h][next_w] = min(flip[next_h][next_w], flip[h][w])
    if S[H - 1][W - 1] == "#":
        flip[H - 1][W - 1] += 1
    # 操作の回数は白と黒が入れ替わった回数の半分（切り捨て）である
    print((flip[H - 1][W - 1] // 2))


if __name__ == "__main__":
    resolve()

import sys

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7


def resolve():
    H, W = list(map(int, input().split()))
    grid = [list("." + eval(input())) for _ in range(H)]
    dp = [[f_inf] * (W + 1) for _ in range(H)]
    dp[0][0] = 0
    for h in range(H):
        for w in range(W + 1):
            if w == 0:
                if h != 0:
                    continue
                next_h, next_w = h, w + 1
                if grid[h][w] == "." and grid[next_h][next_w] == "#":
                    dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)
                elif grid[h][w] == "." and grid[next_h][next_w] == "#":
                    dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)
                else:
                    dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w])
            else:
                for dh, dw in [(1, 0), (0, 1)]:
                    next_h, next_w = h + dh, w + dw
                    if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W + 1:
                        continue
                    if grid[h][w] == "." and grid[next_h][next_w] == "#":
                        dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)
                    elif grid[h][w] == "." and grid[next_h][next_w] == "#":
                        dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1)
                    else:
                        dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w])
    print((dp[-1][-1]))


if __name__ == "__main__":
    resolve()

-from collections import deque -    S = [list(eval(input())) for _ in range(H)] -    # 白と黒が入れ替わった箇所をカウントする -    flip = [[f_inf for _ in range(W)] for _ in range(H)] -    if S[0][0] == "#": -        flip[0][0] = 1 -    else: -        flip[0][0] = 0 -    que = deque([[0, 0]]) -    while que: -        h, w = que.popleft() -        for dh, dw in ((0, 1), (1, 0)): -            next_h, next_w = h + dh, w + dw -            if next_h >= H or next_w >= W: -                continue -            if flip[next_h][next_w] == f_inf: -                que.append([next_h, next_w]) -            # 白と黒が入れ替わったらカウントアップ -            if S[h][w] != S[next_h][next_w]: -                flip[next_h][next_w] = min(flip[next_h][next_w], flip[h][w] + 1) +    grid = [list("." + eval(input())) for _ in range(H)] +    dp = [[f_inf] * (W + 1) for _ in range(H)] +    dp[0][0] = 0 +    for h in range(H): +        for w in range(W + 1): +            if w == 0: +                if h != 0: +                    continue +                next_h, next_w = h, w + 1 +                if grid[h][w] == "." and grid[next_h][next_w] == "#": +                    dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1) +                elif grid[h][w] == "." and grid[next_h][next_w] == "#": +                    dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1) +                else: +                    dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w]) -                flip[next_h][next_w] = min(flip[next_h][next_w], flip[h][w]) -    if S[H - 1][W - 1] == "#": -        flip[H - 1][W - 1] += 1 -    # 操作の回数は白と黒が入れ替わった回数の半分（切り捨て）である -    print((flip[H - 1][W - 1] // 2)) +                for dh, dw in [(1, 0), (0, 1)]: +                    next_h, next_w = h + dh, w + dw +                    if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W + 1: +                        continue +                    if grid[h][w] == "." and grid[next_h][next_w] == "#": +                        dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1) +                    elif grid[h][w] == "." and grid[next_h][next_w] == "#": +                        dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1) +                    else: +                        dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w]) +    print((dp[-1][-1]))