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 << [0,x,y]
            1
        else
            0
        end
    }
}

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

puts n