H,W = (gets).split(" ").map{ |i| i.to_i }
$arr = []
$blks = []
H.times do |h|
    $arr[h] = Array.new(W) {0}
    ta = (gets).delete("\n").chars.map{ |c| c=='#' ? 1 : 0 }
    ta.each_with_index do |t,w|
        if t==1 then
            $arr[h][w] = 1
            $blks << [w,h]
        end
    end
end

# blks基準で仲間を増やしていく
# 仲間を増やせなければ終わる
def add_black(w,h)
    if w>0 then
        $blks << [w-1,h] if ($arr[h][w-1]==0)
        $arr[h][w-1] = 1
    end
    if w<W-1 then
        $blks << [w+1,h] if ($arr[h][w+1]==0)
        $arr[h][w+1] = 1
    end
    if h>0 then
        $blks << [w,h-1] if ($arr[h-1][w]==0)
        $arr[h-1][w] = 1
    end
    if h<H-1 then
        $blks << [w,h+1] if ($arr[h+1][w]==0)
        $arr[h+1][w] = 1
    end
end

count = 0
while $blks.length > 0
    #p $blks
    bs = $blks.shift($blks.length)
    bs.each do |black|
        add_black(black[0], black[1])
    end
    count = count + 1
end

puts count-1
