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

  a=p=s[0]

  dp[0]=b=q=5-a

  for i in range(w):

    t=s[i]

    b+=a^t

    dp[i]=b

    a=t

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

    t=s[i]

    q+=p^t

    dp[i]=b=q

    a=p=t

    k=i-w

    for j in range(i+1,i+w):

      sj=s[j]

      b+=a^sj

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

      k+=1

      if b>t:b=t

      dp[j]=b

      a=sj

  print((b+1>>1))

main()
def main():

  import sys

  input=sys.stdin.buffer.readline

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

  t,*s,_=eval(input())

  if t==46:c,f=0,False

  else:c,f=1,True

  p=[(c,f)]

  for t in s:

    g=t==35

    if g!=f:

      c+=1

      f=not f

    p+=(c,f),

  d=p

  for _ in range(h-1):

    t,*s,_=eval(input())

    c,f=d[0]

    g=t==35

    if g!=f:

      c+=1

      f=not f

    p=[(c,f)]

    for i,t in enumerate(s,1):

      e,h=d[i]

      g=t==35

      if h!=g:

        e+=1

        h=not h

      if f!=g:

        c+=1

        f=not f

      if e<c:

        c,f=e,h

      p+=(c,f),

    d=p

  print((d[-1][0]+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
    a = p = s[0]
    dp[0] = b = q = 5 - a
    for i in range(w):
        t = s[i]
        b += a ^ t
        dp[i] = b
        a = t
    for i in range(x, h * x, x):
        t = s[i]
        q += p ^ t
        dp[i] = b = q
        a = p = t
        k = i - w
        for j in range(i + 1, i + w):
            sj = s[j]
            b += a ^ sj
            t = dp[k] + (s[k] ^ sj)
            k += 1
            if b > t:
                b = t
            dp[j] = b
            a = sj
    print((b + 1 >> 1))


main()

def main():
    import sys

    input = sys.stdin.buffer.readline
    h, w = list(map(int, input().split()))
    t, *s, _ = eval(input())
    if t == 46:
        c, f = 0, False
    else:
        c, f = 1, True
    p = [(c, f)]
    for t in s:
        g = t == 35
        if g != f:
            c += 1
            f = not f
        p += ((c, f),)
    d = p
    for _ in range(h - 1):
        t, *s, _ = eval(input())
        c, f = d[0]
        g = t == 35
        if g != f:
            c += 1
            f = not f
        p = [(c, f)]
        for i, t in enumerate(s, 1):
            e, h = d[i]
            g = t == 35
            if h != g:
                e += 1
                h = not h
            if f != g:
                c += 1
                f = not f
            if e < c:
                c, f = e, h
            p += ((c, f),)
        d = p
    print((d[-1][0] + 1 >> 1))


main()

-    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 -    a = p = s[0] -    dp[0] = b = q = 5 - a -    for i in range(w): -        t = s[i] -        b += a ^ t -        dp[i] = b -        a = t -    for i in range(x, h * x, x): -        t = s[i] -        q += p ^ t -        dp[i] = b = q -        a = p = t -        k = i - w -        for j in range(i + 1, i + w): -            sj = s[j] -            b += a ^ sj -            t = dp[k] + (s[k] ^ sj) -            k += 1 -            if b > t: -                b = t -            dp[j] = b -            a = sj -    print((b + 1 >> 1)) +    input = sys.stdin.buffer.readline +    h, w = list(map(int, input().split())) +    t, *s, _ = eval(input()) +    if t == 46: +        c, f = 0, False +    else: +        c, f = 1, True +    p = [(c, f)] +    for t in s: +        g = t == 35 +        if g != f: +            c += 1 +            f = not f +        p += ((c, f),) +    d = p +    for _ in range(h - 1): +        t, *s, _ = eval(input()) +        c, f = d[0] +        g = t == 35 +        if g != f: +            c += 1 +            f = not f +        p = [(c, f)] +        for i, t in enumerate(s, 1): +            e, h = d[i] +            g = t == 35 +            if h != g: +                e += 1 +                h = not h +            if f != g: +                c += 1 +                f = not f +            if e < c: +                c, f = e, h +            p += ((c, f),) +        d = p +    print((d[-1][0] + 1 >> 1))