M = 9999999
h, w = gets.chomp!.split(" ").map!(&:to_i)
a_hw = Array.new(h) {|index| gets.chomp.chars } 
max_hw = Array.new(h) {|index| Array.new(w, M) }

black = []
a_hw.each_with_index do |arr, h2|
    arr.each_with_index do |ch, w2|
        if ch == "#"
            black.unshift([h2, w2, 0])
        end
    end
end

#puts black
#puts max_hw.map {|x| x.join(",") }

while black.empty?.!
    h2, w2, count = black.shift
    next if max_hw[h2][w2] != M

    max_hw[h2][w2] = count
    count += 1
    #puts h2
    #puts w2
    #puts count
    #puts ""
    #puts max_hw.map {|x| x.join(",") }
    #puts ""
    
    if h2 != 0 
        black.push([h2 - 1, w2, count])
    end
    if h2 != h - 1
        black.push([h2 + 1, w2, count])
    end
    if w2 != 0 
        black.push([h2, w2 - 1, count])
    end
    if w2 != w - 1
        black.push([h2, w2 + 1, count])
    end
end

#puts i
#puts max_hw.map {|x| x.join(",") }
puts max_hw.map{|x| x.max }.max
