local h, w = io.read("*n", "*n", "*l")
local map = {}
for i = 1, h do
  local s = io.read()
  for j = 1, w do
    map[(i - 1) * w + j] = s:sub(j, j) == "."
  end
end

local taskstate = {}
for i = 1, h * w do taskstate[i] = false end
local tasks = {}
local tasknum = 0
local done = 0
local tasklim = h * w

local function addtask(idx)
  if not taskstate[idx] then
    taskstate[idx] = true
    tasknum = tasknum + 1
    local taskidx = tasknum % tasklim
    if taskidx == 0 then taskidx = tasklim end
    tasks[taskidx] = idx
  end
end

local inf = 1000000007
local len = {}
for i = 1, h * w do
  len[i] = inf
end
if not map[1] then
  len[1] = 1
else
  len[1] = 0
end


local function walk(src, dst)
  if map[src] == map[dst] then
    if len[src] < len[dst] then
      len[dst] = len[src]
      addtask(dst)
    end
  else
    if len[src] + 1 < len[dst] then
      len[dst] = len[src] + 1
      addtask(dst)
    end
  end
end

addtask(1)

while done < tasknum do
  done = done + 1
  local taskidx = done % tasklim
  if taskidx == 0 then taskidx = tasklim end
  local idx = tasks[taskidx]
  taskstate[idx] = false

  if idx <= (h - 1) * w then walk(idx, idx + w) end
  if 1 < w then
    if idx % w ~= 0 then walk(idx, idx + 1) end
  end
end
local ret = len[h * w]
print(math.ceil(ret / 2))
