from collections import deque

t,*g=open(0)

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

vis=[[1e9]*w for _ in range(h)]

vis[0][0]=int(g[0][0]=="#")

q=deque([(0,0,vis[0][0])])

while q:

	cy,cx,c=q.popleft()

	for ny,nx in ((cy+1,cx),(cy,cx+1)):

		cc=c

		if not (0<=ny<h and 0<=nx<w):

			continue

		if g[cy][cx]=="." and g[ny][nx]=="#":

			cc+=1

		if cc<vis[ny][nx]:

			vis[ny][nx]=cc

			q.append((ny,nx,cc))

#print(vis)

print((vis[-1][-1]))
from collections import deque

t,*g=open(0)

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

vis=[[1e9]*w for _ in range(h)]

vis[0][0]=int(g[0][0]=="#")

q=deque([(0,0)])

while q:

	cy,cx=q.popleft()

	for ny,nx in ((cy+1,cx),(cy,cx+1)):

		if not not (0<=ny<h and 0<=nx<w) and vis[cy][cx]+(g[cy][cx]!=g[ny][nx]=="#")<vis[ny][nx]:

			vis[ny][nx]=vis[cy][cx]+(g[cy][cx]!=g[ny][nx]=="#")

			q.append((ny,nx))

print((vis[-1][-1]))
from collections import deque

t, *g = open(0)
h, w = list(map(int, t.split()))
vis = [[1e9] * w for _ in range(h)]
vis[0][0] = int(g[0][0] == "#")
q = deque([(0, 0, vis[0][0])])
while q:
    cy, cx, c = q.popleft()
    for ny, nx in ((cy + 1, cx), (cy, cx + 1)):
        cc = c
        if not (0 <= ny < h and 0 <= nx < w):
            continue
        if g[cy][cx] == "." and g[ny][nx] == "#":
            cc += 1
        if cc < vis[ny][nx]:
            vis[ny][nx] = cc
            q.append((ny, nx, cc))
# print(vis)
print((vis[-1][-1]))

from collections import deque

t, *g = open(0)
h, w = list(map(int, t.split()))
vis = [[1e9] * w for _ in range(h)]
vis[0][0] = int(g[0][0] == "#")
q = deque([(0, 0)])
while q:
    cy, cx = q.popleft()
    for ny, nx in ((cy + 1, cx), (cy, cx + 1)):
        if (
            not not (0 <= ny < h and 0 <= nx < w)
            and vis[cy][cx] + (g[cy][cx] != g[ny][nx] == "#") < vis[ny][nx]
        ):
            vis[ny][nx] = vis[cy][cx] + (g[cy][cx] != g[ny][nx] == "#")
            q.append((ny, nx))
print((vis[-1][-1]))

-q = deque([(0, 0, vis[0][0])]) +q = deque([(0, 0)]) -    cy, cx, c = q.popleft() +    cy, cx = q.popleft() -        cc = c -        if not (0 <= ny < h and 0 <= nx < w): -            continue -        if g[cy][cx] == "." and g[ny][nx] == "#": -            cc += 1 -        if cc < vis[ny][nx]: -            vis[ny][nx] = cc -            q.append((ny, nx, cc)) -# print(vis) +        if ( +            not not (0 <= ny < h and 0 <= nx < w) +            and vis[cy][cx] + (g[cy][cx] != g[ny][nx] == "#") < vis[ny][nx] +        ): +            vis[ny][nx] = vis[cy][cx] + (g[cy][cx] != g[ny][nx] == "#") +            q.append((ny, nx))