H,W=gets.split.map(&:to_i)

q = []
map = H.times.map { |y|
    s = gets.chomp
    s.each_char.with_index.map {|c,x|
        if c == '#'
            q << [x,y]
            1
        else
            0
        end
    }
}

n = 0
until q.empty?
    x,y = q.shift
    n = map[y][x] + 1
    q << [x-1,y] if 0 < x && map[y][x-1] == 0 && map[y][x-1] = n
    q << [x+1,y] if x < W-1 && map[y][x+1] == 0 && map[y][x+1] = n
    q << [x,y-1] if 0 < y && map[y-1][x] == 0 && map[y-1][x] = n
    q << [x,y+1] if y < H-1 && map[y+1][x] == 0 && map[y+1][x] = n
end

puts n - 2