local h, w = io.read("*n", "*n", "*l")
local tasks = {}
local len = {}
for i = 1, h do
  s = io.read()
  for j = 1, w do
    local idx = (i - 1) * w + j
    if s:sub(j, j) == "#" then
      len[idx] = 0
      table.insert(tasks, idx)
    else
      len[idx] = 1000000007
    end
  end
end
local done = 0

local function walk(src, dst)
  if len[src] + 1 < len[dst] then
    len[dst] = len[src] + 1
    table.insert(tasks, dst)
  end
end

while done < #tasks do
  done = done + 1
  local idx = tasks[done]
  if w < idx then walk(idx, idx - w) end
  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
    if idx % w ~= 1 then walk(idx, idx - 1) end
  end
end
local ans = len[1]
for i = 2, h * w do
  ans = math.max(ans, len[i])
end
print(ans)
