def main():

  import sys

  b=sys.stdin.buffer

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

  x=w+1

  s=[c>>3for c in b.read()]

  dp=[10001]*h*x

  dp[0]=5-s[0]

  for i in range(1,w):

    dp[i]=dp[i-1]+(s[i-1]^s[i])

  for i in range(x,h*x,x):

    dp[i]=dp[i-x]+(s[i-x]^s[i])

    for j in range(1,w):

      k=i+j

      t=dp[k-1]+(s[k-1]^s[k])

      u=dp[k-x]+(s[k-x]^s[k])

      if t>u:t=u

      dp[k]=t

  print((dp[-2]+1>>1))

main()
def main():

  import sys

  b=sys.stdin.buffer

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

  x=w+1

  s=[c>>3for c in b.read()]

  dp=[10000]*h*x

  dp[0]=5-s[0]

  for i in range(1,w):

    dp[i]=dp[i-1]+(s[i-1]^s[i])

  for i in range(x,h*x,x):

    l=i-x

    dp[i]=dp[l]+(s[l]^s[i])

    for j in range(1,w):

      k=i+j

      l=k-1

      t=dp[l]+(s[l]^s[k])

      l=k-x

      u=dp[l]+(s[l]^s[k])

      if t>u:t=u

      dp[k]=t

  print((dp[-2]+1>>1))

main()
def main():
    import sys

    b = sys.stdin.buffer
    h, w = list(map(int, b.readline().split()))
    x = w + 1
    s = [c >> 3 for c in b.read()]
    dp = [10001] * h * x
    dp[0] = 5 - s[0]
    for i in range(1, w):
        dp[i] = dp[i - 1] + (s[i - 1] ^ s[i])
    for i in range(x, h * x, x):
        dp[i] = dp[i - x] + (s[i - x] ^ s[i])
        for j in range(1, w):
            k = i + j
            t = dp[k - 1] + (s[k - 1] ^ s[k])
            u = dp[k - x] + (s[k - x] ^ s[k])
            if t > u:
                t = u
            dp[k] = t
    print((dp[-2] + 1 >> 1))


main()

def main():
    import sys

    b = sys.stdin.buffer
    h, w = list(map(int, b.readline().split()))
    x = w + 1
    s = [c >> 3 for c in b.read()]
    dp = [10000] * h * x
    dp[0] = 5 - s[0]
    for i in range(1, w):
        dp[i] = dp[i - 1] + (s[i - 1] ^ s[i])
    for i in range(x, h * x, x):
        l = i - x
        dp[i] = dp[l] + (s[l] ^ s[i])
        for j in range(1, w):
            k = i + j
            l = k - 1
            t = dp[l] + (s[l] ^ s[k])
            l = k - x
            u = dp[l] + (s[l] ^ s[k])
            if t > u:
                t = u
            dp[k] = t
    print((dp[-2] + 1 >> 1))


main()

-    dp = [10001] * h * x +    dp = [10000] * h * x -        dp[i] = dp[i - x] + (s[i - x] ^ s[i]) +        l = i - x +        dp[i] = dp[l] + (s[l] ^ s[i]) -            t = dp[k - 1] + (s[k - 1] ^ s[k]) -            u = dp[k - x] + (s[k - x] ^ s[k]) +            l = k - 1 +            t = dp[l] + (s[l] ^ s[k]) +            l = k - x +            u = dp[l] + (s[l] ^ s[k])