local ior = io.input()
local h, w = ior:read("*n", "*n", "*l")
local map = {}
for i = 1, h * w do map[i] = 0 end
local str = ""

local function getidx(wid, hgt)
  return (hgt - 1) * w + wid
end

local tasks = {}
local tasknum = 0
local done = 0

for i = 1, h do
  str = ior:read()
  for j = 1, w do
    local idx = getidx(i, j)
    if(str:sub(j, j) == ".") then
      map[idx] = 3000
    else
      table.insert(tasks, idx)
      tasknum = tasknum + 1
    end
  end
end

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

while(done < tasknum) do
  done = done + 1
  local curidx = tasks[done]
  if(w < curidx) then walk(curidx, curidx - w) end
  if(curidx <= w * (h - 1)) then walk(curidx, curidx + w) end
  if(curidx % w ~= 0) then walk(curidx, curidx + 1) end
  if(curidx % w ~= 1) then walk(curidx, curidx - 1) end
end
local max = 0
local mma = math.max
for i = 1, h * w do
  max = mma(max, map[i])
end
print(max)
