import sequtils, strutils, tables, sets

var h, w = 0
(h, w) = stdin.readLine.split.map parseInt

type TheTable = seq[seq[bool]]

var t: TheTable = @[]

for i in countup(1, h):
  var line = stdin.readLine
  var row = line.toSeq.mapIt (it == '#')
  t.add row

var res: int
proc forward(t: TheTable, c: bool, r, y, x: int)
proc forward(t: TheTable, c: bool, r, y, x: int) =
  if x >= w or y >= h:
    return
  elif t[y][x] == c:
    if x == w-1 and y == h-1:
      if r == 0:
        echo 0
        quit(0)
      elif res == 0:
        res = r
      else:
        res = min(r, res)
    else:
      t.forward(c, r, y, x+1)
      t.forward(c, r, y+1, x)
  else:
    # reverse
    if c:
      t.forward(not c, r+1, y, x)
    else:
      t.forward(not c, r, y, x)
    

t.forward(true, 0, 0, 0)

echo res
