n,k = gets.split.map(&:to_i) player = (n - 1) % (k + 1) p player STDOUT.flush while gets.to_i < n player += k + 1 p player STDOUT.flush end