def main():

  import sys

  input=sys.stdin.buffer.readline

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

  s=eval(input())

  a=x=s[0]>>3

  b=y=5-a

  d=[(b,a)]

  for i in range(1,w):

    f=s[i]>>3

    b+=a^f

    a=f

    d+=(b,a),

  for _ in range(1,h):

    s=eval(input())

    f=s[0]>>3

    y+=x^f

    b=y

    a=x=f

    p=[(b,a)]

    for i in range(1,w):

      f=s[i]>>3

      b+=a^f

      c,g=d[i]

      c+=f^g

      if b>c:b=c

      a=f

      p+=(b,a),

    d=p

  print((b+1>>1))

main()
def main():

  import sys

  input=sys.stdin.buffer.readline

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

  s=eval(input())

  a=b=x=y=s[0]==35

  d=[(b,a)]

  for i in range(1,w):

    f=s[i]==35

    b+=a^f

    a=f

    d+=(b,a),

  for _ in range(1,h):

    s=eval(input())

    f=s[0]==35

    y+=x^f

    b=y

    a=x=f

    p=[(b,a)]

    for i in range(1,w):

      f=s[i]==35

      b+=a^f

      c,g=d[i]

      c+=f^g

      if b>c:b=c

      a=f

      p+=(b,a),

    d=p

  print((b+1>>1))

main()
def main():
    import sys

    input = sys.stdin.buffer.readline
    h, w = list(map(int, input().split()))
    s = eval(input())
    a = x = s[0] >> 3
    b = y = 5 - a
    d = [(b, a)]
    for i in range(1, w):
        f = s[i] >> 3
        b += a ^ f
        a = f
        d += ((b, a),)
    for _ in range(1, h):
        s = eval(input())
        f = s[0] >> 3
        y += x ^ f
        b = y
        a = x = f
        p = [(b, a)]
        for i in range(1, w):
            f = s[i] >> 3
            b += a ^ f
            c, g = d[i]
            c += f ^ g
            if b > c:
                b = c
            a = f
            p += ((b, a),)
        d = p
    print((b + 1 >> 1))


main()

def main():
    import sys

    input = sys.stdin.buffer.readline
    h, w = list(map(int, input().split()))
    s = eval(input())
    a = b = x = y = s[0] == 35
    d = [(b, a)]
    for i in range(1, w):
        f = s[i] == 35
        b += a ^ f
        a = f
        d += ((b, a),)
    for _ in range(1, h):
        s = eval(input())
        f = s[0] == 35
        y += x ^ f
        b = y
        a = x = f
        p = [(b, a)]
        for i in range(1, w):
            f = s[i] == 35
            b += a ^ f
            c, g = d[i]
            c += f ^ g
            if b > c:
                b = c
            a = f
            p += ((b, a),)
        d = p
    print((b + 1 >> 1))


main()

-    a = x = s[0] >> 3 -    b = y = 5 - a +    a = b = x = y = s[0] == 35 -        f = s[i] >> 3 +        f = s[i] == 35 -        f = s[0] >> 3 +        f = s[0] == 35 -            f = s[i] >> 3 +            f = s[i] == 35