import heapq



H,W=list(map(int,input().split()))



mat=[]

for i in range(H):

  array=[x=='.' for x in eval(input())]

  mat.append(array)

#print(mat)



#convert mat to graph

#(i0,j0)->(i1,j1,dist)

graph={}

if mat[0][0]:

  graph[(0,0)]=[(1,1,0)]

else:

  graph[(0,0)]=[(1,1,1)]

  

for i in range(H):

  for j in range(W):

    graph[(i+1,j+1)]=[]

    if mat[i][j]:

      if i<H-1:

        if mat[i+1][j]:

          graph[(i+1,j+1)].append((i+2,j+1,0))

        else:

          graph[(i+1,j+1)].append((i+2,j+1,1))

      if j<W-1:

        if mat[i][j+1]:

          graph[(i+1,j+1)].append((i+1,j+2,0))

        else:

          graph[(i+1,j+1)].append((i+1,j+2,1))

    else:

      if i<H-1:

        graph[(i+1,j+1)].append((i+2,j+1,0))

      if j<W-1:

        graph[(i+1,j+1)].append((i+1,j+2,0))

#print(graph)



# init used,queue,dist

dist={}

hq=[]

dist[(0,0)]=0

heapq.heappush(hq,(0,0,0))

for i in range(1,H+1):

  for j in range(1,W+1):

    dist[(i,j)]=10**9

    heapq.heappush(hq,(i+j,i,j))

#print(queue)



#dkjstra

while(True):

  if len(hq)==0:

    break



  ij,ii,jj=heapq.heappop(hq)

  

  candlist=graph[(ii,jj)]

  for cand in candlist:

    xx,yy,dd=cand

    dist[(xx,yy)]=min(dist[(xx,yy)],dist[(ii,jj)]+dd)

  

print((dist[(H,W)]))
import heapq



H,W=list(map(int,input().split()))



mat=[]

for i in range(H):

  array=[x=='.' for x in eval(input())]

  mat.append(array)

#print(mat)



dist=[]

for i in range(H):

  dist.append([-1]*W)



if mat[0][0]:

  dist[0][0]=0

else:

  dist[0][0]=1

  

for i in range(1,H):

  if mat[i-1][0] and not mat[i][0]:

    dist[i][0]=dist[i-1][0]+1

  else:

    dist[i][0]=dist[i-1][0]

    

for j in range(1,W):

  if mat[0][j-1] and not mat[0][j]:

    dist[0][j]=dist[0][j-1]+1

  else:

    dist[0][j]=dist[0][j-1]

    

for i in range(1,H):

  for j in range(1,W):

    if mat[i-1][j] and not mat[i][j]:

      dist1=dist[i-1][j]+1

    else:

      dist1=dist[i-1][j]

    

    if mat[i][j-1] and not mat[i][j]:

      dist2=dist[i][j-1]+1

    else:

      dist2=dist[i][j-1]

      

    dist[i][j]=min(dist1,dist2)

    

#print(dist)

print((dist[H-1][W-1]))
import heapq

H, W = list(map(int, input().split()))
mat = []
for i in range(H):
    array = [x == "." for x in eval(input())]
    mat.append(array)
# print(mat)
# convert mat to graph
# (i0,j0)->(i1,j1,dist)
graph = {}
if mat[0][0]:
    graph[(0, 0)] = [(1, 1, 0)]
else:
    graph[(0, 0)] = [(1, 1, 1)]
for i in range(H):
    for j in range(W):
        graph[(i + 1, j + 1)] = []
        if mat[i][j]:
            if i < H - 1:
                if mat[i + 1][j]:
                    graph[(i + 1, j + 1)].append((i + 2, j + 1, 0))
                else:
                    graph[(i + 1, j + 1)].append((i + 2, j + 1, 1))
            if j < W - 1:
                if mat[i][j + 1]:
                    graph[(i + 1, j + 1)].append((i + 1, j + 2, 0))
                else:
                    graph[(i + 1, j + 1)].append((i + 1, j + 2, 1))
        else:
            if i < H - 1:
                graph[(i + 1, j + 1)].append((i + 2, j + 1, 0))
            if j < W - 1:
                graph[(i + 1, j + 1)].append((i + 1, j + 2, 0))
# print(graph)
# init used,queue,dist
dist = {}
hq = []
dist[(0, 0)] = 0
heapq.heappush(hq, (0, 0, 0))
for i in range(1, H + 1):
    for j in range(1, W + 1):
        dist[(i, j)] = 10**9
        heapq.heappush(hq, (i + j, i, j))
# print(queue)
# dkjstra
while True:
    if len(hq) == 0:
        break
    ij, ii, jj = heapq.heappop(hq)
    candlist = graph[(ii, jj)]
    for cand in candlist:
        xx, yy, dd = cand
        dist[(xx, yy)] = min(dist[(xx, yy)], dist[(ii, jj)] + dd)
print((dist[(H, W)]))

import heapq

H, W = list(map(int, input().split()))
mat = []
for i in range(H):
    array = [x == "." for x in eval(input())]
    mat.append(array)
# print(mat)
dist = []
for i in range(H):
    dist.append([-1] * W)
if mat[0][0]:
    dist[0][0] = 0
else:
    dist[0][0] = 1
for i in range(1, H):
    if mat[i - 1][0] and not mat[i][0]:
        dist[i][0] = dist[i - 1][0] + 1
    else:
        dist[i][0] = dist[i - 1][0]
for j in range(1, W):
    if mat[0][j - 1] and not mat[0][j]:
        dist[0][j] = dist[0][j - 1] + 1
    else:
        dist[0][j] = dist[0][j - 1]
for i in range(1, H):
    for j in range(1, W):
        if mat[i - 1][j] and not mat[i][j]:
            dist1 = dist[i - 1][j] + 1
        else:
            dist1 = dist[i - 1][j]
        if mat[i][j - 1] and not mat[i][j]:
            dist2 = dist[i][j - 1] + 1
        else:
            dist2 = dist[i][j - 1]
        dist[i][j] = min(dist1, dist2)
# print(dist)
print((dist[H - 1][W - 1]))

-# convert mat to graph -# (i0,j0)->(i1,j1,dist) -graph = {} +dist = [] +for i in range(H): +    dist.append([-1] * W) -    graph[(0, 0)] = [(1, 1, 0)] +    dist[0][0] = 0 -    graph[(0, 0)] = [(1, 1, 1)] -for i in range(H): -    for j in range(W): -        graph[(i + 1, j + 1)] = [] -        if mat[i][j]: -            if i < H - 1: -                if mat[i + 1][j]: -                    graph[(i + 1, j + 1)].append((i + 2, j + 1, 0)) -                else: -                    graph[(i + 1, j + 1)].append((i + 2, j + 1, 1)) -            if j < W - 1: -                if mat[i][j + 1]: -                    graph[(i + 1, j + 1)].append((i + 1, j + 2, 0)) -                else: -                    graph[(i + 1, j + 1)].append((i + 1, j + 2, 1)) +    dist[0][0] = 1 +for i in range(1, H): +    if mat[i - 1][0] and not mat[i][0]: +        dist[i][0] = dist[i - 1][0] + 1 +    else: +        dist[i][0] = dist[i - 1][0] +for j in range(1, W): +    if mat[0][j - 1] and not mat[0][j]: +        dist[0][j] = dist[0][j - 1] + 1 +    else: +        dist[0][j] = dist[0][j - 1] +for i in range(1, H): +    for j in range(1, W): +        if mat[i - 1][j] and not mat[i][j]: +            dist1 = dist[i - 1][j] + 1 -            if i < H - 1: -                graph[(i + 1, j + 1)].append((i + 2, j + 1, 0)) -            if j < W - 1: -                graph[(i + 1, j + 1)].append((i + 1, j + 2, 0)) -# print(graph) -# init used,queue,dist -dist = {} -hq = [] -dist[(0, 0)] = 0 -heapq.heappush(hq, (0, 0, 0)) -for i in range(1, H + 1): -    for j in range(1, W + 1): -        dist[(i, j)] = 10**9 -        heapq.heappush(hq, (i + j, i, j)) -# print(queue) -# dkjstra -while True: -    if len(hq) == 0: -        break -    ij, ii, jj = heapq.heappop(hq) -    candlist = graph[(ii, jj)] -    for cand in candlist: -        xx, yy, dd = cand -        dist[(xx, yy)] = min(dist[(xx, yy)], dist[(ii, jj)] + dd) -print((dist[(H, W)])) +            dist1 = dist[i - 1][j] +        if mat[i][j - 1] and not mat[i][j]: +            dist2 = dist[i][j - 1] + 1 +        else: +            dist2 = dist[i][j - 1] +        dist[i][j] = min(dist1, dist2) +# print(dist) +print((dist[H - 1][W - 1]))