def main():

    from collections import deque



    WHITE = 0

    BLACK = 1



    CHAR = '.', '#'



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

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



    h = deque()

    x = CHAR.index(s[0][0])

    h.append((x, 0, 0, x))



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

    cost[0][0] = x



    while h:

        cnt, r, c, mode = h.popleft()

        if cnt > cost[r][c]:

            continue

        if r == H - 1 and c == W - 1:

            print(cnt)

            return



        delta = int(mode == WHITE)

        ncnt = cnt + delta



        if r < H - 1:

            if s[r + 1][c] == CHAR[mode]:

                if cnt < cost[r + 1][c]:

                    cost[r + 1][c] = cnt

                    h.appendleft((cnt, r + 1, c, mode))

            else:

                if delta:

                    if ncnt < cost[r + 1][c]:

                        cost[r + 1][c] = ncnt

                        h.append((ncnt, r + 1, c, 1 - mode))

                else:

                    if ncnt < cost[r + 1][c]:

                        cost[r + 1][c] = ncnt

                        h.appendleft((ncnt, r + 1, c, 1 - mode))



        if c < W - 1:

            if s[r][c + 1] == CHAR[mode]:

                if cnt < cost[r][c + 1]:

                    cost[r][c + 1] = cnt

                    h.appendleft((cnt, r, c + 1, mode))

            else:

                if delta:

                    if ncnt < cost[r][c + 1]:

                        cost[r][c + 1] = ncnt

                        h.append((ncnt, r, c + 1, 1 - mode))

                else:

                    if ncnt < cost[r][c + 1]:

                        cost[r][c + 1] = ncnt

                        h.appendleft((ncnt, r, c + 1, 1 - mode))





if __name__ == '__main__':

    main()



# import sys

#

# input = sys.stdin.readline

# sys.setrecursionlimit(10 ** 7)

# rstrip()

# int(input())

# map(int, input().split())

def main():

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

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



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



    dp[0][0] = int(s[0][0] == '#')



    for r in range(H):

        for c in range(W):

            if r > 0:

                dp[r][c] = min(dp[r][c], dp[r - 1][c] + int(s[r][c] == '#' and s[r - 1][c] == '.'))

            if c > 0:

                dp[r][c] = min(dp[r][c], dp[r][c - 1] + int(s[r][c] == '#' and s[r][c - 1] == '.'))



    res = dp[H - 1][W - 1]

    print(res)

    return





if __name__ == '__main__':

    main()

def main():
    from collections import deque

    WHITE = 0
    BLACK = 1
    CHAR = ".", "#"
    H, W = list(map(int, input().split()))
    s = [eval(input()) for _ in range(H)]
    h = deque()
    x = CHAR.index(s[0][0])
    h.append((x, 0, 0, x))
    cost = [[H * W] * W for _ in range(H)]
    cost[0][0] = x
    while h:
        cnt, r, c, mode = h.popleft()
        if cnt > cost[r][c]:
            continue
        if r == H - 1 and c == W - 1:
            print(cnt)
            return
        delta = int(mode == WHITE)
        ncnt = cnt + delta
        if r < H - 1:
            if s[r + 1][c] == CHAR[mode]:
                if cnt < cost[r + 1][c]:
                    cost[r + 1][c] = cnt
                    h.appendleft((cnt, r + 1, c, mode))
            else:
                if delta:
                    if ncnt < cost[r + 1][c]:
                        cost[r + 1][c] = ncnt
                        h.append((ncnt, r + 1, c, 1 - mode))
                else:
                    if ncnt < cost[r + 1][c]:
                        cost[r + 1][c] = ncnt
                        h.appendleft((ncnt, r + 1, c, 1 - mode))
        if c < W - 1:
            if s[r][c + 1] == CHAR[mode]:
                if cnt < cost[r][c + 1]:
                    cost[r][c + 1] = cnt
                    h.appendleft((cnt, r, c + 1, mode))
            else:
                if delta:
                    if ncnt < cost[r][c + 1]:
                        cost[r][c + 1] = ncnt
                        h.append((ncnt, r, c + 1, 1 - mode))
                else:
                    if ncnt < cost[r][c + 1]:
                        cost[r][c + 1] = ncnt
                        h.appendleft((ncnt, r, c + 1, 1 - mode))


if __name__ == "__main__":
    main()
# import sys
#
# input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 7)
# rstrip()
# int(input())
# map(int, input().split())

def main():
    H, W = list(map(int, input().split()))
    s = [eval(input()) for _ in range(H)]
    dp = [[H * W] * W for _ in range(H)]
    dp[0][0] = int(s[0][0] == "#")
    for r in range(H):
        for c in range(W):
            if r > 0:
                dp[r][c] = min(
                    dp[r][c], dp[r - 1][c] + int(s[r][c] == "#" and s[r - 1][c] == ".")
                )
            if c > 0:
                dp[r][c] = min(
                    dp[r][c], dp[r][c - 1] + int(s[r][c] == "#" and s[r][c - 1] == ".")
                )
    res = dp[H - 1][W - 1]
    print(res)
    return


if __name__ == "__main__":
    main()

-    from collections import deque - -    WHITE = 0 -    BLACK = 1 -    CHAR = ".", "#" -    h = deque() -    x = CHAR.index(s[0][0]) -    h.append((x, 0, 0, x)) -    cost = [[H * W] * W for _ in range(H)] -    cost[0][0] = x -    while h: -        cnt, r, c, mode = h.popleft() -        if cnt > cost[r][c]: -            continue -        if r == H - 1 and c == W - 1: -            print(cnt) -            return -        delta = int(mode == WHITE) -        ncnt = cnt + delta -        if r < H - 1: -            if s[r + 1][c] == CHAR[mode]: -                if cnt < cost[r + 1][c]: -                    cost[r + 1][c] = cnt -                    h.appendleft((cnt, r + 1, c, mode)) -            else: -                if delta: -                    if ncnt < cost[r + 1][c]: -                        cost[r + 1][c] = ncnt -                        h.append((ncnt, r + 1, c, 1 - mode)) -                else: -                    if ncnt < cost[r + 1][c]: -                        cost[r + 1][c] = ncnt -                        h.appendleft((ncnt, r + 1, c, 1 - mode)) -        if c < W - 1: -            if s[r][c + 1] == CHAR[mode]: -                if cnt < cost[r][c + 1]: -                    cost[r][c + 1] = cnt -                    h.appendleft((cnt, r, c + 1, mode)) -            else: -                if delta: -                    if ncnt < cost[r][c + 1]: -                        cost[r][c + 1] = ncnt -                        h.append((ncnt, r, c + 1, 1 - mode)) -                else: -                    if ncnt < cost[r][c + 1]: -                        cost[r][c + 1] = ncnt -                        h.appendleft((ncnt, r, c + 1, 1 - mode)) +    dp = [[H * W] * W for _ in range(H)] +    dp[0][0] = int(s[0][0] == "#") +    for r in range(H): +        for c in range(W): +            if r > 0: +                dp[r][c] = min( +                    dp[r][c], dp[r - 1][c] + int(s[r][c] == "#" and s[r - 1][c] == ".") +                ) +            if c > 0: +                dp[r][c] = min( +                    dp[r][c], dp[r][c - 1] + int(s[r][c] == "#" and s[r][c - 1] == ".") +                ) +    res = dp[H - 1][W - 1] +    print(res) +    return -# import sys -# -# input = sys.stdin.readline -# sys.setrecursionlimit(10 ** 7) -# rstrip() -# int(input()) -# map(int, input().split())