import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

 

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

S = ''.join(read().decode().split())

 

INF = 10 ** 9

N = H*W

U = 250

dp = [[INF] * U for _ in range(N)]

# そのマスをいじる回数 → 総回数の最小値

dp[0] = list(range(U))

for n in range(H*W):

    for i in range(U-1,0,-1):

        if dp[n][i-1]> dp[n][i]:

            dp[n][i-1] = dp[n][i]

    for i in range(1,U):

        if dp[n][i-1] + 1 < dp[n][i]:

            dp[n][i] = dp[n][i-1] + 1

    s = S[n]

    if s == '#':

        for i in range(0,U,2):

            dp[n][i] = INF

    else:

        for i in range(1,U,2):

            dp[n][i] = INF

    x,y = divmod(n,W)

    to = []

    if y < W - 1:

        to.append(n+1)

    if x < H - 1:

        to.append(n+W)

    for m in to:

        for i in range(U):

            if dp[m][i] > dp[n][i]:

                dp[m][i] = dp[n][i]

 

print((min(dp[-1])))
# https://atcoder.jp/contests/agc043/tasks/agc043_a



import sys

# sys.setrecursionlimit(100000)





def input():

    return sys.stdin.readline().strip()





def input_int():

    return int(eval(input()))





def input_int_list():

    return [int(i) for i in input().split()]





ans = (100 * 100) + 1





def main():

    global ans

    h, w = input_int_list()

    grid = []

    grid.append(["#"] * (w + 2))

    for _ in range(h):

        grid.append(["#"] + list(eval(input())) + ["#"])

    grid.append(["#"] * (w + 2))



    dp = [[101 for _ in range(w + 2)] for _ in range(h + 2)]

    if grid[1][1] == "#":

        dp[1][1] = 1

    else:

        dp[1][1] = 0

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

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

            # 上のマスからくる場合を評価

            if i > 1:

                if grid[i - 1][j] == "." and grid[i][j] == "#":

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

                else:

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



            # 左のマスからくる場合を評価

            if j > 1:

                if grid[i][j - 1] == "." and grid[i][j] == "#":

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

                else:

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



    print((dp[h][w]))

    return





if __name__ == "__main__":

    main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
H, W = list(map(int, readline().split()))
S = "".join(read().decode().split())
INF = 10**9
N = H * W
U = 250
dp = [[INF] * U for _ in range(N)]
# そのマスをいじる回数 → 総回数の最小値
dp[0] = list(range(U))
for n in range(H * W):
    for i in range(U - 1, 0, -1):
        if dp[n][i - 1] > dp[n][i]:
            dp[n][i - 1] = dp[n][i]
    for i in range(1, U):
        if dp[n][i - 1] + 1 < dp[n][i]:
            dp[n][i] = dp[n][i - 1] + 1
    s = S[n]
    if s == "#":
        for i in range(0, U, 2):
            dp[n][i] = INF
    else:
        for i in range(1, U, 2):
            dp[n][i] = INF
    x, y = divmod(n, W)
    to = []
    if y < W - 1:
        to.append(n + 1)
    if x < H - 1:
        to.append(n + W)
    for m in to:
        for i in range(U):
            if dp[m][i] > dp[n][i]:
                dp[m][i] = dp[n][i]
print((min(dp[-1])))

# https://atcoder.jp/contests/agc043/tasks/agc043_a
import sys

# sys.setrecursionlimit(100000)
def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(eval(input()))


def input_int_list():
    return [int(i) for i in input().split()]


ans = (100 * 100) + 1


def main():
    global ans
    h, w = input_int_list()
    grid = []
    grid.append(["#"] * (w + 2))
    for _ in range(h):
        grid.append(["#"] + list(eval(input())) + ["#"])
    grid.append(["#"] * (w + 2))
    dp = [[101 for _ in range(w + 2)] for _ in range(h + 2)]
    if grid[1][1] == "#":
        dp[1][1] = 1
    else:
        dp[1][1] = 0
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            # 上のマスからくる場合を評価
            if i > 1:
                if grid[i - 1][j] == "." and grid[i][j] == "#":
                    dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j])
                else:
                    dp[i][j] = min(dp[i][j], dp[i - 1][j])
            # 左のマスからくる場合を評価
            if j > 1:
                if grid[i][j - 1] == "." and grid[i][j] == "#":
                    dp[i][j] = min(dp[i][j - 1] + 1, dp[i][j])
                else:
                    dp[i][j] = min(dp[i][j - 1], dp[i][j])
    print((dp[h][w]))
    return


if __name__ == "__main__":
    main()

+# https://atcoder.jp/contests/agc043/tasks/agc043_a -read = sys.stdin.buffer.read -readline = sys.stdin.buffer.readline -readlines = sys.stdin.buffer.readlines -H, W = list(map(int, readline().split())) -S = "".join(read().decode().split()) -INF = 10**9 -N = H * W -U = 250 -dp = [[INF] * U for _ in range(N)] -# そのマスをいじる回数 → 総回数の最小値 -dp[0] = list(range(U)) -for n in range(H * W): -    for i in range(U - 1, 0, -1): -        if dp[n][i - 1] > dp[n][i]: -            dp[n][i - 1] = dp[n][i] -    for i in range(1, U): -        if dp[n][i - 1] + 1 < dp[n][i]: -            dp[n][i] = dp[n][i - 1] + 1 -    s = S[n] -    if s == "#": -        for i in range(0, U, 2): -            dp[n][i] = INF +# sys.setrecursionlimit(100000) +def input(): +    return sys.stdin.readline().strip() + + +def input_int(): +    return int(eval(input())) + + +def input_int_list(): +    return [int(i) for i in input().split()] + + +ans = (100 * 100) + 1 + + +def main(): +    global ans +    h, w = input_int_list() +    grid = [] +    grid.append(["#"] * (w + 2)) +    for _ in range(h): +        grid.append(["#"] + list(eval(input())) + ["#"]) +    grid.append(["#"] * (w + 2)) +    dp = [[101 for _ in range(w + 2)] for _ in range(h + 2)] +    if grid[1][1] == "#": +        dp[1][1] = 1 -        for i in range(1, U, 2): -            dp[n][i] = INF -    x, y = divmod(n, W) -    to = [] -    if y < W - 1: -        to.append(n + 1) -    if x < H - 1: -        to.append(n + W) -    for m in to: -        for i in range(U): -            if dp[m][i] > dp[n][i]: -                dp[m][i] = dp[n][i] -print((min(dp[-1]))) +        dp[1][1] = 0 +    for i in range(1, h + 1): +        for j in range(1, w + 1): +            # 上のマスからくる場合を評価 +            if i > 1: +                if grid[i - 1][j] == "." and grid[i][j] == "#": +                    dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j]) +                else: +                    dp[i][j] = min(dp[i][j], dp[i - 1][j]) +            # 左のマスからくる場合を評価 +            if j > 1: +                if grid[i][j - 1] == "." and grid[i][j] == "#": +                    dp[i][j] = min(dp[i][j - 1] + 1, dp[i][j]) +                else: +                    dp[i][j] = min(dp[i][j - 1], dp[i][j]) +    print((dp[h][w])) +    return + + +if __name__ == "__main__": +    main()