from heapq import*

def main():

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

  s=[eval(input())for _ in range(h)]

  g=h*w+1

  e=[[]for _ in range(g)]

  for i in range(h):

    for j in range(w):

      for y,x in((i+1,j),(i,j+1)):

        if y<h and x<w:

          if s[i][j]=='.'and s[y][x]!='.':

            e[i*w+j]+=(1,y*w+x),

          else:

            e[i*w+j]+=(0,y*w+x),

  e[g-1]+=(s[0][0]!='.',0),

  q=[g-1]

  d=[10**12]*g

  while q:

    c=heappop(q)

    c,v=c//g,c%g

    if c>d[v]:continue

    d[v]=c

    for x,w in e[v]:

      x+=c

      if d[w]>x:

        d[w]=x

        heappush(q,x*g+w)

  print((d[g-2]))

main()
h,*s=open(0)

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

dp=[[9e9]*w for _ in s]

dp[0][0]=s[0][0]<'.'

for i in range(h*w):

  i,j=i//w,i%w

  for y,x in((i+1,j),(i,j+1)):

    if y<h and x<w:dp[y][x]=min(dp[y][x],dp[i][j]+(s[i][j]=='.'>s[y][x]))

print((dp[-1][-1]))
from heapq import *


def main():
    h, w = list(map(int, input().split()))
    s = [eval(input()) for _ in range(h)]
    g = h * w + 1
    e = [[] for _ in range(g)]
    for i in range(h):
        for j in range(w):
            for y, x in ((i + 1, j), (i, j + 1)):
                if y < h and x < w:
                    if s[i][j] == "." and s[y][x] != ".":
                        e[i * w + j] += ((1, y * w + x),)
                    else:
                        e[i * w + j] += ((0, y * w + x),)
    e[g - 1] += ((s[0][0] != ".", 0),)
    q = [g - 1]
    d = [10**12] * g
    while q:
        c = heappop(q)
        c, v = c // g, c % g
        if c > d[v]:
            continue
        d[v] = c
        for x, w in e[v]:
            x += c
            if d[w] > x:
                d[w] = x
                heappush(q, x * g + w)
    print((d[g - 2]))


main()

h, *s = open(0)
h, w = list(map(int, h.split()))
dp = [[9e9] * w for _ in s]
dp[0][0] = s[0][0] < "."
for i in range(h * w):
    i, j = i // w, i % w
    for y, x in ((i + 1, j), (i, j + 1)):
        if y < h and x < w:
            dp[y][x] = min(dp[y][x], dp[i][j] + (s[i][j] == "." > s[y][x]))
print((dp[-1][-1]))

-from heapq import * - - -def main(): -    h, w = list(map(int, input().split())) -    s = [eval(input()) for _ in range(h)] -    g = h * w + 1 -    e = [[] for _ in range(g)] -    for i in range(h): -        for j in range(w): -            for y, x in ((i + 1, j), (i, j + 1)): -                if y < h and x < w: -                    if s[i][j] == "." and s[y][x] != ".": -                        e[i * w + j] += ((1, y * w + x),) -                    else: -                        e[i * w + j] += ((0, y * w + x),) -    e[g - 1] += ((s[0][0] != ".", 0),) -    q = [g - 1] -    d = [10**12] * g -    while q: -        c = heappop(q) -        c, v = c // g, c % g -        if c > d[v]: -            continue -        d[v] = c -        for x, w in e[v]: -            x += c -            if d[w] > x: -                d[w] = x -                heappush(q, x * g + w) -    print((d[g - 2])) - - -main() +h, *s = open(0) +h, w = list(map(int, h.split())) +dp = [[9e9] * w for _ in s] +dp[0][0] = s[0][0] < "." +for i in range(h * w): +    i, j = i // w, i % w +    for y, x in ((i + 1, j), (i, j + 1)): +        if y < h and x < w: +            dp[y][x] = min(dp[y][x], dp[i][j] + (s[i][j] == "." > s[y][x])) +print((dp[-1][-1]))