local function str2tbl(s)
    local t = {string.byte(s, 1, #s)}
    for i=1, #t do
        t[i] = string.char(t[i])
    end
    return t
end

------
local H, W = io.read("*n", "*n", "*l")
local grid = {}
local distance = {}
for i=1, H do
    grid[i] = str2tbl(io.read("*l"))
    distance[i] = {}
    for j=1, W do
        distance[i][j] = 2001
    end
end
--[[
for i=1, H do
    for j=1, W do
        print(i,j, grid[i][j])
    end
end
]]
local blacks = {}
for i=1, H do
    for j=1, W do
        local c = grid[i][j]
        if c == '#' then
            table.insert(blacks, {i, j})
        end
    end
end
for _, t in ipairs(blacks) do
    local i, j = t[1], t[2]
    distance[i][j] = 0
end
local function dfs(d, i, j)
    d = d + 1
    local x, y
    x, y = i-1, j
    if x >= 1 and distance[x][y] > d then
        distance[x][y] = d
        dfs(d, x, y)
    end
    x, y = i+1, j
    if x <= H and distance[x][y] > d then
        distance[x][y] = d
        dfs(d, x, y)
    end
    x, y = i, j-1
    if y >= 1 and distance[x][y] > d then
        distance[x][y] = d
        dfs(d, x, y)
    end
    x, y = i, j+1
    if y <= W and distance[x][y] > d then
        distance[x][y] = d
        dfs(d, x, y)
    end
end
for _, t in ipairs(blacks) do
    local i, j = t[1], t[2]
    dfs(0, i, j)
end
local dmax = 0
for i=1, H do
    for j=1, W do
        dmax = math.max(distance[i][j], dmax)
    end
end
print(dmax)