import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


H,W = m()

po = [list(input()) for i in range(H)]

aaa = [[[mod,0] for i in range(W)] for j in range(H)]
aa = [[[mod,0] for i in range(W)] for j in range(H)]

if po[0][0] == "#":
    aaa[0][0] = [1,3]
else:
    aaa[0][0] = [0,0]

for i in range(H):
    if i == 0:
        for j in range(1,W):
            if po[i][j] == "#":
                if aaa[i][j-1][1] == 0:
                    aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0]+1)
                    aaa[i][j][1] = 3
                elif aaa[i][j-1][1] == 1 or aaa[i][j-1][1] == 3:
                    aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0])
                    aaa[i][j][1] = 3
            else:
                aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0])

    else:
        for j in range(W):
            if j == 0:
                if po[i][j] == "#":
                    if aaa[i-1][j][1] == 0:
                        aaa[i][j][0] = min(aaa[i][j][0],aaa[i-1][j][0]+1)
                        aaa[i][j][1] = 3
                    elif aaa[i-1][j][1] == 3 or aaa[i-1][j][1] == 2:
                        aaa[i][j][0] = min(aaa[i][j][0],aaa[i-1][j][0])
                        aaa[i][j][1] = 3
                else:
                    aaa[i][j][0] = min(aaa[i][j][0],aaa[i-1][j][0])
            else:
                if po[i][j] == "#":
                    if aaa[i-1][j][1] == 0 or aaa[i-1][j][1] == 1:
                        if aaa[i][j-1][1] == 0 or aaa[i][j-1][1] == 2:
                            aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0]+1,aaa[i-1][j][0]+1)
                            aaa[i][j][1] = 3
                        elif aaa[i][j-1][1] == 1:
                            aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0],aaa[i-1][j][0]+1)
                            aaa[i][j][1] = 3
                        elif aaa[i][j-1][1] == 3:
                            aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0],aaa[i-1][j][0]+1)
                            aaa[i][j][1] = 3
                    elif aaa[i-1][j][1] == 2:
                        if aaa[i][j-1][1] == 0 or aaa[i][j-1][1] == 2:
                            aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0]+1,aaa[i-1][j][0])
                            aaa[i][j][1] = 3
                        elif aaa[i][j-1][1] == 1:
                            aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0],aaa[i-1][j][0])
                            aaa[i][j][1] = 3
                        elif aaa[i][j-1][1] == 3:
                            aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0],aaa[i-1][j][0])
                            aaa[i][j][1] = 3
                    elif aaa[i-1][j][1] == 3:
                        if aaa[i][j-1][1] == 0 or aaa[i][j-1][1] == 2:
                            aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0]+1,aaa[i-1][j][0])
                            aaa[i][j][1] = 3
                        elif aaa[i][j-1][1] == 1:
                            aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0],aaa[i-1][j][0])
                            aaa[i][j][1] = 3
                        elif aaa[i][j-1][1] == 3:
                            aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0],aaa[i-1][j][0])
                            aaa[i][j][1] = 3
                else:
                    aaa[i][j][0] = min(aaa[i][j][0],aaa[i][j-1][0],aaa[i-1][j][0])

if po[0][0] == ".":
    aa[0][0] = [2,3]
else:
    aa[0][0] = [1,0]

for i in range(H):
    if i == 0:
        for j in range(1,W):
            if po[i][j] == ".":
                if aa[i][j-1][1] == 0:
                    aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0]+1)
                    aa[i][j][1] = 3
                elif aa[i][j-1][1] == 1 or aa[i][j-1][1] == 3:
                    aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0])
                    aa[i][j][1] = 1
            else:
                aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0])

    else:
        for j in range(W):
            if j == 0:
                if po[i][j] == ".":
                    if aa[i-1][j][1] == 0:
                        aa[i][j][0] = min(aa[i][j][0],aa[i-1][j][0]+1)
                        aa[i][j][1] = 3
                    elif aa[i-1][j][1] == 3 or aa[i-1][j][1] == 2:
                        aa[i][j][0] = min(aa[i][j][0],aa[i-1][j][0])
                        aa[i][j][1] = 2
                else:
                    aa[i][j][0] = min(aa[i][j][0],aa[i-1][j][0])
            else:
                if po[i][j] == ".":
                    if aa[i-1][j][1] == 0 or aa[i-1][j][1] == 1:
                        if aa[i][j-1][1] == 0 or aa[i][j-1][1] == 2:
                            aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0]+1,aa[i-1][j][0]+1)
                            aa[i][j][1] = 3
                        elif aa[i][j-1][1] == 1:
                            aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0],aa[i-1][j][0]+1)
                            aa[i][j][1] = 3
                        elif aa[i][j-1][1] == 3:
                            aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0],aa[i-1][j][0]+1)
                            aa[i][j][1] = 3
                    elif aa[i-1][j][1] == 2:
                        if aa[i][j-1][1] == 0 or aa[i][j-1][1] == 2:
                            aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0]+1,aa[i-1][j][0])
                            aa[i][j][1] = 3
                        elif aa[i][j-1][1] == 1:
                            aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0],aa[i-1][j][0])
                            aa[i][j][1] = 3
                        elif aa[i][j-1][1] == 3:
                            aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0],aa[i-1][j][0])
                            aa[i][j][1] = 3
                    elif aa[i-1][j][1] == 3 or aa[i][j-1][1] == 2:
                        if aa[i][j-1][1] == 0:
                            aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0]+1,aa[i-1][j][0])
                            aa[i][j][1] = 3
                        elif aa[i][j-1][1] == 1:
                            aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0],aa[i-1][j][0])
                            aa[i][j][1] = 3
                        elif aa[i][j-1][1] == 3:
                            aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0],aa[i-1][j][0])
                            aa[i][j][1] = 3
                else:
                    aa[i][j][0] = min(aa[i][j][0],aa[i][j-1][0],aa[i-1][j][0])

print(min(aaa[-1][-1][0],aa[-1][-1][0]))





Measured memory_bytes: 50412