require 'matrix'

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, h + w - 2) }

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

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

i = 0

while black.empty?.!
    h2, w2, count = black.shift
    count += 1
    #puts h2
    #puts w2
    #puts count
    #puts ""
    #puts max_hw.map {|x| x.join(",") }
    #puts ""
    if h2 != 0 
        if a_hw[h2 - 1][w2] == '.'
            if max_hw[h2-1][w2] > count
                max_hw[h2-1][w2] = count
                black.push([h2 - 1, w2, count])
            end
        end
    end
    if h2 != h - 1
        if a_hw[h2 + 1][w2] == "."
            if max_hw[h2 + 1][w2] > count
                max_hw[h2+1][w2] = count
                black.push([h2 + 1, w2, count])
            end
        end
    end
    if w2 != 0 
        if a_hw[h2    ][w2 - 1] == "."
            if max_hw[h2][w2 - 1] > count
                max_hw[h2][w2 - 1] = count
                black.push([h2, w2 - 1, count])
            end
        end
    end
    if w2 != w - 1
        if a_hw[h2    ][w2 + 1] == "."
            if max_hw[h2][w2 + 1] > count
                max_hw[h2][w2 + 1] = count
                black.push([h2, w2 + 1, count])
            end
        end
    end
    i += 1
end

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