def main():

    from collections import deque

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

    l = [list(eval(input())) for i in range(h)]



    dp = [[[-1]*(h*w) for i in range(w)] for i in range(h)]

    q = deque([])

    if l[0][0] == ".":

        q.append((0,0,0,"."))

    else:

        q.append((0,0,1,"#"))

    dx = [0,1]

    dy = [1,0]

    while q:

        

        bx,by,num,bef = q.popleft()

        for j in range(2):

            nx = bx+dx[j]

            ny = by+dy[j]

            if nx < h and ny < w:

                if bef == "." and l[nx][ny] == "#":

                    if dp[nx][ny][num+1] == -1:

                    

                        dp[nx][ny][num+1] = 1

                        q.append((nx,ny,num+1,l[nx][ny]))

                elif dp[nx][ny][num] == -1:

                    dp[nx][ny][num] = 1

                    q.append((nx,ny,num,l[nx][ny]))



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

if __name__ == "__main__":

    main()



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

l = [list(eval(input())) for i in range(h)]



dp = [[-1]*w for i in range(h)]

if l[0][0] == ".":

    dp[0][0] = 0

else:

    dp[0][0] = 1



for i in range(h):

    for j in range(w):

        if i == 0 and j == 0:

            continue



        if i == 0:

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

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

            else:

                dp[i][j] = dp[i][j-1]

        elif j == 0:

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

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

            else:

                dp[i][j] = dp[i-1][j]

        else:

            a = dp[i-1][j]

            b = dp[i][j-1] 

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

                a += 1

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

                b += 1

            dp[i][j] = min(a,b)

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

         

            
def main():
    from collections import deque

    h, w = list(map(int, input().split()))
    l = [list(eval(input())) for i in range(h)]
    dp = [[[-1] * (h * w) for i in range(w)] for i in range(h)]
    q = deque([])
    if l[0][0] == ".":
        q.append((0, 0, 0, "."))
    else:
        q.append((0, 0, 1, "#"))
    dx = [0, 1]
    dy = [1, 0]
    while q:
        bx, by, num, bef = q.popleft()
        for j in range(2):
            nx = bx + dx[j]
            ny = by + dy[j]
            if nx < h and ny < w:
                if bef == "." and l[nx][ny] == "#":
                    if dp[nx][ny][num + 1] == -1:
                        dp[nx][ny][num + 1] = 1
                        q.append((nx, ny, num + 1, l[nx][ny]))
                elif dp[nx][ny][num] == -1:
                    dp[nx][ny][num] = 1
                    q.append((nx, ny, num, l[nx][ny]))
    print((dp[-1][-1].index(1)))


if __name__ == "__main__":
    main()

h, w = list(map(int, input().split()))
l = [list(eval(input())) for i in range(h)]
dp = [[-1] * w for i in range(h)]
if l[0][0] == ".":
    dp[0][0] = 0
else:
    dp[0][0] = 1
for i in range(h):
    for j in range(w):
        if i == 0 and j == 0:
            continue
        if i == 0:
            if l[i][j - 1] == "." and l[i][j] == "#":
                dp[i][j] = dp[i][j - 1] + 1
            else:
                dp[i][j] = dp[i][j - 1]
        elif j == 0:
            if l[i - 1][j] == "." and l[i][j] == "#":
                dp[i][j] = dp[i - 1][j] + 1
            else:
                dp[i][j] = dp[i - 1][j]
        else:
            a = dp[i - 1][j]
            b = dp[i][j - 1]
            if l[i - 1][j] == "." and l[i][j] == "#":
                a += 1
            if l[i][j - 1] == "." and l[i][j] == "#":
                b += 1
            dp[i][j] = min(a, b)
print((dp[-1][-1]))

-def main(): -    from collections import deque - -    h, w = list(map(int, input().split())) -    l = [list(eval(input())) for i in range(h)] -    dp = [[[-1] * (h * w) for i in range(w)] for i in range(h)] -    q = deque([]) -    if l[0][0] == ".": -        q.append((0, 0, 0, ".")) -    else: -        q.append((0, 0, 1, "#")) -    dx = [0, 1] -    dy = [1, 0] -    while q: -        bx, by, num, bef = q.popleft() -        for j in range(2): -            nx = bx + dx[j] -            ny = by + dy[j] -            if nx < h and ny < w: -                if bef == "." and l[nx][ny] == "#": -                    if dp[nx][ny][num + 1] == -1: -                        dp[nx][ny][num + 1] = 1 -                        q.append((nx, ny, num + 1, l[nx][ny])) -                elif dp[nx][ny][num] == -1: -                    dp[nx][ny][num] = 1 -                    q.append((nx, ny, num, l[nx][ny])) -    print((dp[-1][-1].index(1))) - - -if __name__ == "__main__": -    main() +h, w = list(map(int, input().split())) +l = [list(eval(input())) for i in range(h)] +dp = [[-1] * w for i in range(h)] +if l[0][0] == ".": +    dp[0][0] = 0 +else: +    dp[0][0] = 1 +for i in range(h): +    for j in range(w): +        if i == 0 and j == 0: +            continue +        if i == 0: +            if l[i][j - 1] == "." and l[i][j] == "#": +                dp[i][j] = dp[i][j - 1] + 1 +            else: +                dp[i][j] = dp[i][j - 1] +        elif j == 0: +            if l[i - 1][j] == "." and l[i][j] == "#": +                dp[i][j] = dp[i - 1][j] + 1 +            else: +                dp[i][j] = dp[i - 1][j] +        else: +            a = dp[i - 1][j] +            b = dp[i][j - 1] +            if l[i - 1][j] == "." and l[i][j] == "#": +                a += 1 +            if l[i][j - 1] == "." and l[i][j] == "#": +                b += 1 +            dp[i][j] = min(a, b) +print((dp[-1][-1]))