import queue

class VInfo(object):
    def __init__(self,color,x,y,d,isChange):
        if not isChange:
            self.color=color
            self.d=d
        else:
            if color==".":self.color="#"
            else:self.color="."
            self.d=d+1
        self.x=x
        self.y=y

h,w=map(int,input().split())
a=[[str(i) for i in input()] for j in range(h)]
sx,sy=0,0
gx,gy=w-1,h-1
cw=0


mapA=[]
m=100000000000000
for my in range(h):
    l=[]
    for mx in range(w):
        if a[my][mx]=="#":l.append(VInfo("#",mx,my,m,False))
        else:l.append(VInfo(".",mx,my,m,False))
    mapA.append(l)
q=queue.Queue()
if a[0][0]==".":q.put(VInfo(a[0][0],sx,sy,0,False))
else:q.put(VInfo(a[0][0],sx,sy,1,True))
while not q.empty():
    now=q.get()
    if now.x==gx and now.y==gy:
        if now.color=="." and a[gy][gx]==".":m=min(m,now.d)
        if now.color=="#" and a[gy][gx]==".":m=min(m,now.d)
        if now.color=="." and a[gy][gx]=="#":m=min(m,now.d)+2
        if now.color=="#" and a[gy][gx]=="#":m=min(m,now.d)+2

    if now.y+1<w and a[now.y+1][now.x]==now.color:
        if mapA[now.y+1][now.x].d>now.d:
            mapA[now.y+1][now.x].d=now.d
            q.put(VInfo(now.color,now.x,now.y+1,now.d,False))
    if now.y+1<w and a[now.y+1][now.x]!=now.color:
        if mapA[now.y+1][now.x].d>now.d:
            mapA[now.y+1][now.x].d=now.d
            q.put(VInfo(now.color,now.x,now.y+1,now.d,True))

    if now.x+1<h and a[now.y][now.x+1]==now.color:
        if mapA[now.y][now.x+1].d>now.d:
            mapA[now.y][now.x+1].d=now.d
            q.put(VInfo(now.color,now.x+1,now.y,now.d,False))
    if now.x+1<h and a[now.y][now.x+1]!=now.color:
        if mapA[now.y][now.x+1].d>now.d:
            mapA[now.y][now.x+1].d=now.d
            q.put(VInfo(now.color,now.x+1,now.y,now.d,True))

m=m//2
print(m)





### FIXED CODE ###

import queue

class VInfo(object):
    def __init__(self,x,y,d,color):
        self.color=color
        self.d=d
        self.x=x
        self.y=y
    def turnColor(self):
        if self.color==".":return "#"
        else:return "."

h,w=map(int,input().split())
a=[[str(i) for i in input()] for j in range(h)]
sx,sy=0,0
gx,gy=w-1,h-1
cw=0
mapA=[]
m=100000000000000
for my in range(h):
    l=[]
    for mx in range(w):
        l.append(m)
    mapA.append(l)

q=queue.Queue()
if a[0][0]==".":q.put(VInfo(0,0,0,"."))
else:q.put(VInfo(0,0,1,"#"))
l=[]
while not q.empty():
    now=q.get()
    if now.x==gx and now.y==gy:
        if now.color=="#":l.append((mapA[gy][gx]+2)//2)
        else:l.append((mapA[gy][gx]+1)//2)

    if now.y+1<h and a[now.y+1][now.x]==now.color and mapA[now.y+1][now.x]>now.d:
            mapA[now.y+1][now.x]=now.d
            q.put(VInfo(now.x,now.y+1,now.d,now.color))
    if now.y+1<h and a[now.y+1][now.x]!=now.color and mapA[now.y+1][now.x]>now.d:
            mapA[now.y+1][now.x]=now.d
            q.put(VInfo(now.x,now.y+1,now.d+1,now.turnColor()))
    if now.x+1<w and a[now.y][now.x+1]==now.color and mapA[now.y][now.x+1]>now.d:
            mapA[now.y][now.x+1]=now.d
            q.put(VInfo(now.x+1,now.y,now.d,now.color))
    if now.x+1<w and a[now.y][now.x+1]!=now.color and mapA[now.y][now.x+1]>now.d:
            mapA[now.y][now.x+1]=now.d
            q.put(VInfo(now.x+1,now.y,now.d+1,now.turnColor()))
print(min(l))