from itertools import count, repeat



h = int(input().split()[0])

a0 = repeat('.')

r0 = count()

for i in range(h):

  a = eval(input())

  r = [i]

  for x, y, z, u in zip(a0, '.' + a, a, r0):

    r.append(min(u + (x + z == '.#'), r[-1] + (y + z == '.#')))

  a0 = a

  r0 = r[1:]

print((r[-1]))

from itertools import count, repeat



h = int(input().split()[0])

a0 = repeat('.')

r0 = count()

for i in range(h):

  a = eval(input())

  r = [i]

  for x, y, z, u in zip(a0, '.' + a, a, r0):

    r.append(min(u + (x > z), r[-1] + (y > z)))

  a0 = a

  r0 = r[1:]

print((r[-1]))

from itertools import count, repeat

h = int(input().split()[0])
a0 = repeat(".")
r0 = count()
for i in range(h):
    a = eval(input())
    r = [i]
    for x, y, z, u in zip(a0, "." + a, a, r0):
        r.append(min(u + (x + z == ".#"), r[-1] + (y + z == ".#")))
    a0 = a
    r0 = r[1:]
print((r[-1]))

from itertools import count, repeat

h = int(input().split()[0])
a0 = repeat(".")
r0 = count()
for i in range(h):
    a = eval(input())
    r = [i]
    for x, y, z, u in zip(a0, "." + a, a, r0):
        r.append(min(u + (x > z), r[-1] + (y > z)))
    a0 = a
    r0 = r[1:]
print((r[-1]))

-        r.append(min(u + (x + z == ".#"), r[-1] + (y + z == ".#"))) +        r.append(min(u + (x > z), r[-1] + (y > z)))