Buggy python submission (verdict: Time Limit Exceeded):
def inputs(): return [int(x) for x in input().split()]
h,w = inputs()
meiro=[list(input()) for _ in range(h)]
visit = [[-1]*w for _ in range(h)]
#if meiro[0][0]=="#":
#  a = 1
#else:
#  a=0
stk = [[(0,0),(-1,-1),0]]
while stk:
    v,p,cnt = stk.pop()
    vx,vy = v
    px,py = p
    if w<=vx or h<=vy or (visit[vy][vx]!=-1 and visit[vy][vx]<cnt):
        continue
    if py==-1 and px==-1:
      if meiro[vy][vx]=="#":
        visit[vy][vx]=1
        cnt+=1
      else:
        visit[vy][vx]=0
    elif meiro[vy][vx]=="#"  and meiro[py][px]=="#":
        visit[vy][vx] = cnt
    elif meiro[vy][vx]=="#" and meiro[py][px]!="#":
        visit[vy][vx] = cnt+1
        cnt+=1
    elif meiro[vy][vx]==".":
        visit[vy][vx]=cnt
    dx = [0,1]
    dy = [1,0]
    for i in range(2):
        vx1 = vx+dx[i]
        vy1 = vy+dy[i]
        stk.append([(vx1,vy1),(vx,vy),cnt])
print(visit[h-1][w-1])

Fixed submission:
def inputs(): return [int(x) for x in input().split()]
h,w = inputs()
meiro=[list(input()) for _ in range(h)]
visit = [[-1]*w for _ in range(h)]
if meiro[0][0]=="#":
    visit[0][0]=1
else:
    visit[0][0]=0
for j in range(1,w):
    if meiro[0][j]=="#":
        if meiro[0][j-1]=="#":
            visit[0][j]=visit[0][j-1]
        else:
            visit[0][j]=visit[0][j-1]+1
    if meiro[0][j]==".":
        visit[0][j]=visit[0][j-1]
for i in range(1,h):
    if meiro[i][0]=="#":
        if meiro[i-1][0]=="#":
            visit[i][0]=visit[i-1][0]
        else:
            visit[i][0]=visit[i-1][0]+1
    if meiro[i][0]==".":
        visit[i][0]=visit[i-1][0]
#print(visit)
for i in range(1,h):
    for j in range(1,w):
        if meiro[i][j]=="#":
            if meiro[i-1][j]=="#" and meiro[i][j-1]=="#":
                visit[i][j]=min(visit[i-1][j],visit[i][j-1])
            elif meiro[i-1][j]=="#":
                visit[i][j]=min(visit[i-1][j],visit[i][j-1]+1)
            elif meiro[i][j-1]=="#":
                visit[i][j]=min(visit[i-1][j]+1,visit[i][j-1])
            else:
                visit[i][j]=min(visit[i-1][j]+1,visit[i][j-1]+1)
        else:
            visit[i][j]=min(visit[i-1][j],visit[i][j-1])
print(visit[h-1][w-1])

Buggy python submission (verdict: Time Limit Exceeded):
def inputs(): return [int(x) for x in input().split()]
h,w = inputs()
meiro=[list(input()) for _ in range(h)]
visit = [[-1]*w for _ in range(h)]
#if meiro[0][0]=="#":
#  a = 1
#else:
#  a=0
stk = [[(0,0),(-1,-1),0]]
while stk:
    v,p,cnt = stk.pop()
    vx,vy = v
    px,py = p
    if w<=vx or h<=vy or (visit[vy][vx]!=-1 and visit[vy][vx]<cnt):
        continue
    if py==-1 and px==-1:
      if meiro[vy][vx]=="#":
        visit[vy][vx]=1
        cnt+=1
      else:
        visit[vy][vx]=0
    elif meiro[vy][vx]=="#"  and meiro[py][px]=="#":
        visit[vy][vx] = cnt
    elif meiro[vy][vx]=="#" and meiro[py][px]!="#":
        visit[vy][vx] = cnt+1
        cnt+=1
    elif meiro[vy][vx]==".":
        visit[vy][vx]=cnt
    dx = [0,1]
    dy = [1,0]
    for i in range(2):
        vx1 = vx+dx[i]
        vy1 = vy+dy[i]
        stk.append([(vx1,vy1),(vx,vy),cnt])
print(visit[h-1][w-1])

Fixed submission:
def inputs(): return [int(x) for x in input().split()]
h,w = inputs()
meiro=[list(input()) for _ in range(h)]
visit = [[-1]*w for _ in range(h)]
if meiro[0][0]=="#":
    visit[0][0]=1
else:
    visit[0][0]=0
for j in range(1,w):
    if meiro[0][j]=="#":
        if meiro[0][j-1]=="#":
            visit[0][j]=visit[0][j-1]
        else:
            visit[0][j]=visit[0][j-1]+1
    if meiro[0][j]==".":
        visit[0][j]=visit[0][j-1]
for i in range(1,h):
    if meiro[i][0]=="#":
        if meiro[i-1][0]=="#":
            visit[i][0]=visit[i-1][0]
        else:
            visit[i][0]=visit[i-1][0]+1
    if meiro[i][0]==".":
        visit[i][0]=visit[i-1][0]
#print(visit)
for i in range(1,h):
    for j in range(1,w):
        if meiro[i][j]=="#":
            if meiro[i-1][j]=="#" and meiro[i][j-1]=="#":
                visit[i][j]=min(visit[i-1][j],visit[i][j-1])
            elif meiro[i-1][j]=="#":
                visit[i][j]=min(visit[i-1][j],visit[i][j-1]+1)
            elif meiro[i][j-1]=="#":
                visit[i][j]=min(visit[i-1][j]+1,visit[i][j-1])
            else:
                visit[i][j]=min(visit[i-1][j]+1,visit[i][j-1]+1)
        else:
            visit[i][j]=min(visit[i-1][j],visit[i][j-1])
print(visit[h-1][w-1])