A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k* - 1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that flea has infinitely much time for this jumping.
The only line contains single integer: 1 ≤ *n* ≤ 1000 — number of hassocks.
import queue

n, b = list(map(int, input().split()))


class Task:

    def __init__(self, time: int, duration: int, index: int) -> None:
        super().__init__()
        self.time = time
        self.duration = duration
        self.index = index


remaining = queue.Queue()

running = False
finish_time = 0  # Running task with end at finish_time

result = {}
for i in range(n):
    time, duration = list(map(int, input().split()))
    task = Task(time, duration, index=i)
    result.update({i: 0})

    if task.time > finish_time:
        running = False

    if not running and remaining.empty():
        running = True
        finish_time = task.time + task.duration
        result[i] = finish_time
    else:
        if task.time >= finish_time and not remaining.empty():
            task_to_run = remaining.get()
            finish_time += task_to_run.duration
            result[task_to_run.index] = finish_time

        if remaining.qsize() < b:
            remaining.put(task)
        else:
            result[i] = -1

while not remaining.empty():
    task_to_run = remaining.get()
    finish_time += task_to_run.duration
    result[task_to_run.index] = finish_time

for key in result:
    print(result.get(key))
