line = gets.chomp.split(" ").map(&:to_i)
height = line[0]
width = line[1]
a = []
(0..height-1).each do
    a.push(gets.chomp.split(""))
end

b = Marshal.load(Marshal.dump(a))
cnt = 0
(0..height*width-1).each do
    cnt_black = 0
    (0..height-1).each do |h|
        (0..width-1).each do |w|
            if a[h][w] == "#"
                cnt_black += 1
                b[h-1][w] = "#" if h > 0
                b[h][w-1] = "#" if w > 0
                b[h+1][w] = "#" if h + 1 < height
                b[h][w+1] = "#" if w + 1 < width
            end
        end
    end
    break if cnt_black == height * width
    a = Marshal.load(Marshal.dump(b))
    cnt += 1
end

puts cnt