h, w = gets.split(" ").map(&:to_i)
arr = []
pts = []
h.times do |hi|
    wi = 0
    ar = []
    gets.each_char do |c|
        n = (c == "." ? 0 : 1)
        pts << [hi, wi] if n == 1
        ar << n
        wi += 1
    end
    arr << ar
end

count = 0
while pts.length > 0
    new_pts = []
    pts.each do |hi, wi|
        (-1..1).each do |hh|
            (-1..1).each do |ww|
                next if hh == 0 && ww == 0
                next if (hh + ww) % 2 == 0
                p_h = hi + hh
                p_w = wi + ww
                next if p_h < 0 || p_h >= h
                next if p_w < 0 || p_w >= w
                next if arr[p_h][p_w] == 1
                arr[p_h][p_w] = 1
                new_pts << [p_h, p_w]
            end
        end
    end
    pts = new_pts.uniq
    count += 1 if pts.length > 0
end

puts count
