In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.

When a query appears server may react in three possible ways:   If server is free and query queue is empty, then server immediately starts to process this query.  If server is busy and there are less than b queries in the queue, then new query is added to the end of the queue.  If server is busy and there are already b queries pending in the queue, then new query is just rejected and will never be processed. 

As soon as server finished to process some query, it picks new one from the queue (if it's not empty, of course). If a new query comes at some moment x, and the server finishes to process another query at exactly the same moment, we consider that first query is picked from the queue and only then new query appears.

For each query find the moment when the server will finish to process it or print -1 if this query will be rejected.


-----Input-----

The first line of the input contains two integers n and b (1 ≤ n, b ≤ 200 000) — the number of queries and the maximum possible size of the query queue.

Then follow n lines with queries descriptions (in chronological order). Each description consists of two integers t_{i} and d_{i} (1 ≤ t_{i}, d_{i} ≤ 10^9), where t_{i} is the moment of time when the i-th query appears and d_{i} is the time server needs to process it. It is guaranteed that t_{i} - 1 < t_{i} for all i > 1.


-----Output-----

Print the sequence of n integers e_1, e_2, ..., e_{n}, where e_{i} is the moment the server will finish to process the i-th query (queries are numbered in the order they appear in the input) or  - 1 if the corresponding query will be rejected.


-----Examples-----
Input
5 1
2 9
4 8
10 9
15 2
19 1

Output
11 19 -1 21 22 

Input
4 1
2 8
4 8
10 9
15 2

Output
10 18 27 -1 



-----Note-----

Consider the first sample.   The server will start to process first query at the moment 2 and will finish to process it at the moment 11.  At the moment 4 second query appears and proceeds to the queue.  At the moment 10 third query appears. However, the server is still busy with query 1, b = 1 and there is already query 2 pending in the queue, so third query is just rejected.  At the moment 11 server will finish to process first query and will take the second query from the queue.  At the moment 15 fourth query appears. As the server is currently busy it proceeds to the queue.  At the moment 19 two events occur simultaneously: server finishes to proceed the second query and the fifth query appears. As was said in the statement above, first server will finish to process the second query, then it will pick the fourth query from the queue and only then will the fifth query appear. As the queue is empty fifth query is proceed there.  Server finishes to process query number 4 at the moment 21. Query number 5 is picked from the queue.  Server finishes to process query number 5 at the moment 22.

Difficulty: MEDIUM_HARD

Solutions:
from collections import deque
(n, queue_size) = map(lambda x: int(x), input().split())
results = [-1 for _ in range(n)]
next_server_free_time = 1
queue = deque()
for idx in range(n):
	(t, d) = map(lambda x: int(x), input().split())
	while queue and next_server_free_time <= t:
		(idx1, d1) = queue.popleft()
		next_server_free_time += d1
		results[idx1] = next_server_free_time
	if next_server_free_time <= t:
		results[idx] = t + d
		next_server_free_time = t + d
	elif len(queue) < queue_size:
		queue.append((idx, d))
while queue:
	(idx, d) = queue.popleft()
	next_server_free_time += d
	results[idx] = next_server_free_time
print(' '.join(map(lambda x: str(x), results)))


def main():
	from collections import deque
	a = deque()
	(n, b) = map(int, input().split())
	next_t = 0
	for i in range(n):
		(c, lo) = map(int, input().split())
		while a and a[0] <= c:
			a.popleft()
		if len(a) > b:
			print(-1, end=' ')
		else:
			print(max(next_t, c) + lo, end=' ')
			next_t = max(next_t, c) + lo
			a.append(next_t)
main()


(n, b) = map(int, input().split(' '))
Q = []
for _ in range(n):
	(t, d) = map(int, input().split(' '))
	while len(Q) > 0 and Q[0] <= t:
		Q.pop(0)
	L = len(Q) - 1
	if L == b:
		print(-1, end=' ')
		continue
	if not Q:
		Q.append(t + d)
	else:
		Q.append(Q[-1] + d)
	print(Q[-1], end=' ')


def main():
	(n, hi) = map(int, input().split())
	(l, res, lo, hi) = ([0], [], 0, -hi)
	(f, p) = (res.append, l.append)
	for _ in range(n):
		(t, d) = map(int, input().split())
		d += t if t > l[-1] else l[-1]
		while lo <= hi and l[lo] <= t:
			lo += 1
		if hi >= lo:
			f('-1')
		else:
			hi += 1
			p(d)
			f(str(d))
	print(' '.join(res))
main()


(n, b) = map(int, input().split())
ends = []
for i in range(n):
	(t, d) = map(int, input().split())
	while len(ends) > 0 and ends[0] <= t:
		ends.pop(0)
	q = len(ends) - 1
	if q == b:
		print(-1, end=' ')
		continue
	if not ends:
		ends.append(t + d)
	else:
		ends.append(ends[-1] + d)
	print(ends[-1], end=' ')


import queue
(n, b) = map(int, input().split())
q = queue.Queue()
time = 0
for i in range(n):
	(t, d) = map(int, input().split())
	while q.qsize() and q.queue[0] <= t:
		q.get()
	if q.empty():
		time = t
	if q.qsize() <= b:
		time += d
		q.put(time)
		print(time, end=' ')
	else:
		print(-1, end=' ')


from collections import deque
from collections import namedtuple
Query = namedtuple('Query', ['time', 'duration'])
(query_number, max_query_queue_length) = list(map(int, input().split()))
queries = deque((Query(*list(map(int, input().split()))) for i in range(query_number)))
results = {}
query_queue = deque()
current_time = 0
while len(results) != query_number:
	if query_queue:
		query = query_queue.popleft()
	else:
		query = queries.popleft()
	if current_time > query.time:
		current_time += query.duration
	else:
		current_time = query.time + query.duration
	results[query.time] = current_time
	while queries and queries[0].time < current_time:
		if len(query_queue) < max_query_queue_length:
			query_queue.append(queries.popleft())
		else:
			ignored_query = queries.popleft()
			results[ignored_query.time] = -1
print(' '.join((str(results[time]) for time in sorted(results.keys()))))


from collections import deque
(n, b) = [int(x) for x in input().split()]
D = deque()
time = [-1] * n
T = 0
for i in range(n):
	(t, d) = [int(x) for x in input().split()]
	while D and T + D[0][0] <= t:
		T += D[0][0]
		time[D[0][1]] = T
		D.popleft()
	if len(D) == 0:
		T = t
	if len(D) <= b:
		D.append((d, i))
import math
t = float('inf')
while D and T + D[0][0] <= t:
	T += D[0][0]
	time[D[0][1]] = T
	D.popleft()
for t in time:
	print(t, end=' ')


import queue

class query:

	def __init__(self, id, t, d):
		self.id = id
		self.t = t
		self.d = d
q = queue.Queue()
res = 0
(n, mq) = map(int, input().split())
x = []
for i in range(n):
	(t, d) = map(int, input().split())
	x.append((t, d))
a = [-1] * n
q.put(query(0, x[0][0], x[0][1]))
i = 1
while q.qsize() != 0:
	res = max(res, q.queue[0].t) + q.queue[0].d
	a[q.queue[0].id] = res
	q.get()
	while i < n and q.qsize() < mq:
		q.put(query(i, x[i][0], x[i][1]))
		i += 1
	while i < n and res > x[i][0]:
		i += 1
for i in a:
	print(i, end=' ')


import queue
(n, b) = map(int, input().split())
t = []
d = []
for i in range(n):
	(x, y) = map(int, input().split())
	t.append(x)
	d.append(y)
q = queue.Queue()
curTime = 0
ans = [-1] * n
for i in range(n):
	while q.qsize() > 0 and curTime <= t[i]:
		query = q.get()
		curTime += d[query]
		ans[query] = curTime
	curTime = max(curTime, t[i])
	if q.qsize() >= b:
		ans[i] = -1
	else:
		q.put(i)
while not q.empty():
	query = q.get()
	curTime += d[query]
	ans[query] = curTime
for v in ans:
	print('{} '.format(v), end='')


import heapq
(n, b) = map(int, input().split())
ans = [-1 for i in range(n)]
queue = []
head = 0
size = 0
time = 0
for i in range(n):
	(t, d) = map(int, input().split())
	while size != 0 and time <= t:
		time += queue[head][0]
		ans[queue[head][1]] = time
		head += 1
		size -= 1
	if size == b:
		continue
	if size == 0 and time <= t:
		time = t + d
		ans[i] = time
		continue
	queue.append((d, i))
	size += 1
for i in range(head, len(queue)):
	time += queue[i][0]
	ans[queue[i][1]] = time
for x in ans:
	print(x, end=' ')


(n, b) = list(map(int, input().split()))
tasks = []
next_task = 0
time = 0
finish = [-1] * n
for i in range(n):
	(t, d) = list(map(int, input().split()))
	while tasks and next_task < len(tasks) and (time <= t):
		time += tasks[next_task][1]
		finish[tasks[next_task][0]] = time
		next_task += 1
	if len(tasks) - next_task < b:
		tasks.append((i, d))
	time = max(t, time)
while tasks and next_task < len(tasks):
	time += tasks[next_task][1]
	finish[tasks[next_task][0]] = time
	next_task += 1
print(*finish)


(n, b) = [int(i) for i in input().split()]
q = [0] * n
bg = 0
en = 0
time = 0
res = [-1] * n
for it in range(n):
	ev = [int(i) for i in input().split()]
	ev.append(it)
	while bg < en and max(time, q[bg][0]) <= ev[0]:
		time = max(time, q[bg][0])
		res[q[bg][2]] = time + q[bg][1]
		time += q[bg][1]
		bg += 1
	if en - bg < b:
		q[en] = ev
		en += 1
while bg < en:
	time = max(time, q[bg][0])
	res[q[bg][2]] = time + q[bg][1]
	time += q[bg][1]
	bg += 1
for i in range(n):
	print(res[i], end=' ')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
import bisect
from collections import Counter
(n, l) = map(int, input().split())
import bisect
q = []
for i in range(n):
	(ti, du) = map(int, input().split())
	while q and q[0] <= ti:
		q.pop(0)
	if len(q) >= l + 1:
		print(-1, end=' ')
	elif q:
		var = q[-1]
		print(var + du, end=' ')
		q.append(du + var)
	else:
		print(ti + du, end=' ')
		q.append(ti + du)


def main():
	read = lambda : list(map(int, input().split()))
	(n, b) = read()
	from collections import deque
	Q = deque()
	ans = [0] * n
	for i in range(n):
		(t, d) = read()
		while len(Q) > 0 and t >= Q[0]:
			Q.popleft()
		if len(Q) == 0:
			cur = t + d
		elif len(Q) < b + 1:
			cur = Q[-1] + d
		else:
			cur = -1
		ans[i] = cur
		if cur != -1:
			Q.append(cur)
	print(' '.join(map(str, ans)))
main()


(n, size) = map(int, input().split())
queue = []
(head, tail) = (0, 0)
for i in range(n):
	(time, during) = map(int, input().split())
	while head != tail and time >= queue[head]:
		head += 1
	if tail - head - 1 < size:
		if head == tail:
			queue.append(time + during)
		else:
			queue.append(queue[-1] + during)
		print(queue[-1], end=' ')
		tail += 1
	else:
		print('-1', end=' ')


from collections import deque
(n, d) = map(int, input().split())
per = input().split()
t = int(per[0]) + int(per[1])
per = 0
print(t, end=' ')
answer = t
queue = deque()
for i in range(n - 1):
	(per1, per2) = map(int, input().split())
	while t < per1:
		if per >= 1:
			s = queue.pop()
			t += s
			per -= 1
		else:
			t = per1
			answer = t
	if t == per1:
		if per >= 1:
			s = queue.pop()
			per -= 1
			t += s
			if per < d:
				answer += per2
				print(answer, end=' ')
				queue.appendleft(per2)
				per += 1
		else:
			answer = answer + per2
			print(answer, end=' ')
			queue.appendleft(per2)
			per = 1
	elif per < d:
		answer = answer + per2
		queue.appendleft(per2)
		print(answer, end=' ')
		per += 1
	else:
		print(-1, end=' ')


import queue

class Task:

	def __init__(self, t, d, f):
		self.t = t
		self.d = d
		self.f = f
(n, b) = map(int, input().split())
a = []
for i in range(n):
	(t, d) = map(int, input().split())
	a.append(Task(t, d, 0))
q = queue.Queue()
now = a[0].t + a[0].d
a[0].f = now
q.put(now)
i = 1
while i < n:
	task = a[i]
	while q.qsize() > 0 and task.t >= q.queue[0]:
		q.get()
	if q.qsize() > b:
		task.f = -1
	else:
		now = max(task.t, now)
		now += task.d
		task.f = now
		q.put(now)
	i += 1
for i in range(n):
	print(a[i].f, end=' ')


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

def Q():
	a = [0]
	l = 0
	for i in range(n):
		(t, d) = map(int, input().split())
		a += [t + d if t > a[-1] else a[-1] + d]
		while a[l] <= t:
			l += 1
		if len(a) - l - 1 > b:
			a.pop()
			yield '-1'
		else:
			yield str(a[-1])
print(' '.join(Q()))


import queue
(n, b) = map(int, input().split())
result = [0] * n
last_processing = 0
waiting_queue = queue.Queue()
for i in range(n):
	(ti, di) = map(int, input().split())
	while waiting_queue.qsize() > 0 and last_processing <= ti:
		last_processing = max(last_processing, waiting_queue.queue[0]['time']) + waiting_queue.queue[0]['take_time']
		result[waiting_queue.queue[0]['index']] = last_processing
		waiting_queue.get()
	if waiting_queue.qsize() < b:
		waiting_queue.put({'index': i, 'time': ti, 'take_time': di})
	else:
		result[i] = -1
while waiting_queue.qsize() > 0:
	last_processing = max(last_processing, waiting_queue.queue[0]['time']) + waiting_queue.queue[0]['take_time']
	result[waiting_queue.queue[0]['index']] = last_processing
	waiting_queue.get()
print(*result, sep=' ')


import queue
(n, b) = map(int, input().split())
q = queue.Queue()
(processing, qlen) = (0, 0)
for _ in range(n):
	(t, d) = map(int, input().split())
	while qlen != 0 and q.queue[0] <= t:
		q.get()
		qlen -= 1
	if qlen <= b:
		processing = max(processing, t) + d
		print(processing, end=' ')
		q.put(processing)
		qlen += 1
	else:
		print(-1, end=' ')


import sys

def main():
	(n, b) = [int(tok) for tok in sys.stdin.readline().split()]
	td_list = []
	for i in range(n):
		td_list.append([int(tok) for tok in sys.stdin.readline().split()])
	queue = []
	finish = [-1 for i in range(n)]
	for (i, (t, d)) in enumerate(td_list):
		if len(queue) > 0:
			if queue[0] <= t:
				queue.pop(0)
		if len(queue) == 0 or queue[-1] < t:
			queue.append(t + d)
			finish[i] = t + d
		elif len(queue) == b + 1:
			pass
		else:
			finish[i] = queue[-1] + d
			queue.append(queue[-1] + d)
	print(' '.join([str(f) for f in finish]))

def __starting_point():
	main()
__starting_point()


(n, b) = map(int, input().split())
from collections import deque
q = deque()
for i in range(n):
	(t, d) = map(int, input().split())
	while len(q) > 0 and q[0] <= t:
		q.popleft()
	if len(q) <= b:
		r = t if len(q) == 0 else q[-1]
		print(r + d, end=' ')
		q.append(r + d)
	else:
		print(-1, end=' ')


import os
s = input().split(' ')
n = int(s[0])
b = int(s[1])
requests = [[]] * n
for i in range(n):
	s = input().split(' ')
	requests[i] = [int(s[0]), int(s[1])]
result = [0] * n
counter = 1
time = 0
queue = []
time = requests[0][0]
queue = [[0, requests[0][1]]]
while counter < n:
	if len(queue) != 0:
		if queue[0][1] <= requests[counter][0] - time:
			time += queue[0][1]
			result[queue[0][0]] = str(time)
			queue = queue[1:]
		else:
			queue[0][1] -= requests[counter][0] - time
			time = requests[counter][0]
			if len(queue) < b + 1:
				queue += [[counter, requests[counter][1]]]
			else:
				result[counter] = '-1'
			counter += 1
	else:
		time = requests[counter][0]
		queue += [[counter, requests[counter][1]]]
		counter += 1
for i in range(len(queue)):
	time += queue[i][1]
	result[queue[i][0]] = time
print()
s = ''
for i in range(len(result)):
	s += str(result[i]) + ' '
print(s)


import sys
from collections import deque
(n, b) = map(int, sys.stdin.readline().split())
b += 1
q = deque()
res = []
cur_time = 0
for iter in range(n):
	(t, d) = map(int, sys.stdin.readline().split())
	while len(q) > 0 and q[0] <= t:
		q.popleft()
	if len(q) >= b:
		res.append(-1)
		continue
	if len(q) == 0:
		res.append(t + d)
		q.append(t + d)
	else:
		res.append(q[-1] + d)
		q.append(q[-1] + d)
print(' '.join(map(str, res)))


class Query:

	def __init__(self, id, t_toi, t_tt):
		self.id = id
		self.t_toi = t_toi
		self.t_tt = t_tt
import queue
(n, b) = map(int, input().split())
q = queue.Queue()
t_process = 0
ans = [0] * n
for i in range(n):
	(t_toi, t_tt) = map(int, input().split())
	while q.qsize() > 0 and t_toi >= t_process:
		front = q.get()
		t_process += front.t_tt
		ans[front.id] = t_process
	if t_toi > t_process:
		t_process = t_toi + t_tt
		ans[i] = t_process
	elif q.qsize() < b:
		q.put(Query(i, t_toi, t_tt))
	else:
		ans[i] = -1
while q.qsize() > 0:
	front = q.get()
	t_process += front.t_tt
	ans[front.id] = t_process
for i in ans:
	print(i, end=' ')


import queue

def processing_queries(n, b, q):
	result = []
	finished = q[0][0] + q[0][1]
	result.append(finished)
	queries = queue.Queue()
	queries.put(finished)
	for i in range(1, len(q)):
		while queries.qsize() > 0 and q[i][0] >= queries.queue[0]:
			queries.get()
		if finished <= q[i][0]:
			finished = q[i][0] + q[i][1]
			result.append(finished)
			queries.put(finished)
		elif queries.qsize() > b:
			result.append(-1)
		else:
			finished += q[i][1]
			result.append(finished)
			queries.put(finished)
	print(*result)
(n, b) = [int(x) for x in input().split()]
list_of_queries = []
for i in range(n):
	this_q = [int(x) for x in input().split()]
	list_of_queries.append(this_q)
processing_queries(n, b, list_of_queries)


import queue
import sys
sys.setrecursionlimit(100000)
INF = int(10000000.0 + 1)
MAX = 105

def main():
	(n, b) = map(int, input().split())
	(t, d) = ([], [])
	for i in range(n):
		(x, y) = map(int, input().split())
		t.append(x)
		d.append(y)
	t.append(INF)
	d.append(INF)
	actual_time = time_done = 0
	Q = queue.Queue()
	Q.put(0)
	i = 0
	while not Q.empty() or i < n:
		if not Q.empty() and time_done <= actual_time or i == n:
			cur = Q.get()
			t[cur] = max(time_done, t[cur]) + d[cur]
			time_done = t[cur]
		if i != 0 and i != n:
			if Q.qsize() < b:
				Q.put(i)
			else:
				t[i] = -1
		if i != n:
			i += 1
			actual_time = t[i]
	for i in range(n):
		print(t[i], end=' ')
main()


import queue
q = queue.Queue()
ans = [0] * 200000
(n, b) = map(int, input().split())
tmp = 0
ans[0] = tmp
for i in range(n):
	(t, d) = map(int, input().split())
	while q.empty() == False and q.queue[0] <= t:
		q.get()
	if q.qsize() > b:
		ans[i] = -1
	else:
		tmp = max(tmp, t) + d
		ans[i] = tmp
		q.put(tmp)
for i in range(n):
	print(ans[i], end=' ')


(n, queue_size) = [int(x) for x in input().split()]
results = [-1 for _ in range(n)]
next_server_free_time = 1
queue = []
for idx in range(n):
	(t, d) = [int(x) for x in input().split()]
	while queue and next_server_free_time <= t:
		(idx1, d1) = queue.pop(0)
		next_server_free_time += d1
		results[idx1] = next_server_free_time
	if next_server_free_time <= t:
		results[idx] = t + d
		next_server_free_time = t + d
	elif len(queue) < queue_size:
		queue.append((idx, d))
while queue:
	(idx, d) = queue.pop(0)
	next_server_free_time += d
	results[idx] = next_server_free_time
print(' '.join([str(x) for x in results]))


import collections

class TaskMgr:

	def __init__(self, n, b):
		self.b = b
		self.lock_until = 1
		self.q = collections.deque()
		self.end = [-1 for i in range(n)]

	def empty(self):
		return len(self.q) == 0

	def full(self):
		return len(self.q) == self.b

	def add(self, i, t, d):
		if self.full():
			return
		self.q.append((i, t, d))

	def tick(self, now=None):
		if self.empty():
			return
		lock = self.lock_until
		now = now or lock
		if now < lock:
			return
		now = min(lock, now)
		(i, t, d) = self.q.popleft()
		t = max(t, now)
		end = t + d
		self.lock_until = end
		self.end[i] = end

def __starting_point():
	(n, b) = [int(x) for x in input().split()]
	mgr = TaskMgr(n, b)
	for i in range(n):
		(t, d) = [int(x) for x in input().split()]
		mgr.tick(t)
		mgr.add(i, t, d)
	while not mgr.empty():
		mgr.tick()
	print(' '.join((str(x) for x in mgr.end)))
__starting_point()


import sys
q = []
(n, b) = map(int, input().split())
t = 0
d = 0
for i in range(0, n):
	(t, d) = map(int, input().split())
	while len(q) != 0:
		if q[0] <= t:
			q.pop(0)
		else:
			break
	if len(q) <= b:
		if len(q) != 0:
			t = q[-1]
		t = t + d
		print(t, end=' ')
		q.append(t)
	else:
		print(-1, end=' ')


from heapq import heappush, heappop
from collections import deque
(number_jobs, queue_size) = map(int, input().split())
ret = dict()
events = list()
jobs = deque()
for i in range(number_jobs):
	(time, duration) = map(int, input().split())
	heappush(events, (time, 1, i, duration))
while events:
	data = heappop(events)
	if data[1] == 0:
		(finish_time, job_number) = (data[0], data[2])
		ret[job_number] = finish_time
		jobs.popleft()
		if jobs:
			(job, duration) = jobs.popleft()
			jobs.appendleft((job, duration))
			heappush(events, (finish_time + duration, 0, job))
	else:
		(time, job_number, duration) = (data[0], data[2], data[3])
		if len(jobs) <= queue_size:
			if not jobs:
				heappush(events, (time + duration, 0, job_number))
			jobs.append((job_number, duration))
		else:
			ret[job_number] = -1
print(' '.join(map(lambda x: str(ret[x]), sorted(ret))))


def main():
	from sys import stdin
	(n, hi) = map(int, input().split())
	(l, res, lo, hi) = ([0], [], 0, -hi)
	(f, p) = (res.append, l.append)
	for s in stdin.read().splitlines():
		(t, d) = map(int, s.split())
		d += t if t > l[-1] else l[-1]
		while lo <= hi and l[lo] <= t:
			lo += 1
		if hi >= lo:
			f('-1')
		else:
			hi += 1
			p(d)
			f(str(d))
	print(' '.join(res))
main()


import queue

class Query:

	def __init__(self, _id, _t, _d):
		self.id = _id
		self.t = _t
		self.d = _d
(n, b) = map(int, input().split())
ans = [0] * n
q = queue.Queue()
last_time = 0
for i in range(n):
	(t, d) = map(int, input().split())
	while q.qsize() > 0 and t >= last_time:
		front = q.get()
		last_time += front.d
		ans[front.id] = last_time
	if t > last_time:
		last_time = t + d
		ans[i] = last_time
	elif q.qsize() < b:
		q.put(Query(i, t, d))
	else:
		ans[i] = -1
while q.qsize() > 0:
	front = q.get()
	last_time += front.d
	ans[front.id] = last_time
for x in ans:
	print(x, end=' ')


class zapros:

	def __init__(self, t, timeToComplete):
		self.t = t
		self.timeToComplete = timeToComplete
n = input()
b = int(n.split()[1])
n = int(n.split()[0])
zapQueue = []
result = []
timeAfterComplete = 0
sumTime = 0
for i in range(n):
	s = input()
	zapr = zapros(int(s.split(' ')[0]), int(s.split(' ')[1]))
	while timeAfterComplete <= zapr.t and len(zapQueue) > 0:
		obj = zapQueue.pop(0)
		timeAfterComplete += obj.timeToComplete
		sumTime -= obj.timeToComplete
	if timeAfterComplete + sumTime > zapr.t:
		if len(zapQueue) < b:
			sumTime += zapr.timeToComplete
			result.append(timeAfterComplete + sumTime)
			zapQueue.append(zapr)
		else:
			result.append(-1)
	else:
		zapQueue = []
		sumTime = 0
		timeAfterComplete = zapr.t + zapr.timeToComplete
		result.append(timeAfterComplete)
msg = ''
for i in result:
	msg += str(i) + ' '
print(msg[:-1])


from collections import deque
(n, k) = map(int, input().split())
arr = []
for i in range(n):
	(a, b) = map(int, input().split())
	arr.append([a, b, i + 1])
deq = deque([arr[0]])
at = 1
time = arr[0][0]
ans = [-1] * n
while deq:
	(a, b, idx) = deq.popleft()
	if a > time:
		time = a + b
	else:
		time += b
	ans[idx - 1] = time
	while at < n and arr[at][0] < time:
		if len(deq) < k:
			deq.append(arr[at])
		at += 1
	if at < n and len(deq) <= k and (arr[at][0] == time):
		deq.append(arr[at])
		at += 1
	while at < n and len(deq) < k:
		deq.append(arr[at])
		at += 1
print(*ans)


import queue

class Query:

	def __init__(self, t, d, id):
		self.t = t
		self.d = d
		self.id = id
(n, b) = map(int, input().split())
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append(Query(x, y, i))
i = 0
cur_time = 0
q = queue.Queue()
result = [0] * n
while i < n:
	while i < n and a[i].t < cur_time and (q.qsize() < b):
		q.put(a[i])
		i += 1
	while i < n and a[i].t < cur_time and (q.qsize() == b):
		result[i] = -1
		i += 1
	if not q.empty():
		processed_query = q.get()
		cur_time += processed_query.d
		result[processed_query.id] = cur_time
	elif i < n:
		cur_time = a[i].t + a[i].d
		result[a[i].id] = cur_time
		i += 1
while not q.empty():
	processed_query = q.get()
	cur_time += processed_query.d
	result[processed_query.id] = cur_time
for i in range(n):
	print(result[i], end=' ')


(n, b) = map(int, input().split())
from queue import Queue
q = Queue()
begin = []
stay = []
end = []
res = []
proceeding = 0
for i in range(n):
	(t, d) = map(int, input().split())
	begin.append(t)
	stay.append(d)
	end.append(t + d)
	res.append(0)
res[0] += end[0]
q.put(1)
for i in range(2, n):
	if q.qsize() < b:
		q.put(i)
	elif q.qsize() == b:
		if res[proceeding] > begin[i]:
			res[i] = -1
		else:
			x = q.get()
			q.put(i)
			if begin[x] > res[proceeding]:
				res[x] = end[x]
			else:
				res[x] = res[proceeding] + stay[x]
			proceeding = x
	if i == n - 1 and q.qsize() != 0:
		while q.qsize() != 0:
			x = q.get()
			if begin[x] > res[proceeding]:
				res[x] = end[x]
			else:
				res[x] = res[proceeding] + stay[x]
			proceeding = x
for i in range(len(res)):
	print(res[i], end=' ')


import queue
(n, b) = map(int, input().split())
ans = [0] * n
pos = 0
stack = []
wait = queue.Queue()
current = 0
if n <= b:
	_list = []
	for i in range(n):
		x = list(map(int, input().split()))
		_list.append(x)
	ans[0] = _list[0][0] + _list[0][1]
	for i in range(1, n):
		ans[i] = max(ans[i - 1], _list[i][0]) + _list[i][1]
else:
	_list = []
	for j in range(n):
		x = list(map(int, input().split()))
		_list.append(x)
	i = 0
	for j in _list:
		if stack == []:
			stack.append(j)
			ans[pos] = j[0] + j[1]
			pos += 1
			current = 0
		elif j[0] >= ans[current]:
			stack.pop()
			wait.put(j)
			stack.append(wait.get())
			if j[0] > ans[current] and wait.empty():
				ans[pos] = j[0] + stack[0][1]
			else:
				ans[pos] = max(ans[current], stack[0][0]) + stack[0][1]
			current = pos
			pos += 1
			while pos < n - 1 and ans[pos] == -1:
				pos += 1
		elif wait.qsize() < b:
			wait.put(j)
		else:
			ans[i] = -1
		i += 1
	while not wait.empty() and pos != n:
		temp = wait.get()
		ans[pos] = max(temp[0], ans[current]) + temp[1]
		current = pos
		pos += 1
		while pos < n - 1 and ans[pos] == -1:
			pos += 1
for i in range(n):
	print(ans[i], end='')
	if i != n - 1:
		print(' ', end='')


from collections import deque
(n, b) = [int(x) for x in input().split()]
d = deque()
ans = [0] * n
now = 0
j = 0
for i in range(n):
	t = [int(x) for x in input().split()]
	while len(d) != 0 and now <= t[0]:
		if d[0][0] > now:
			now = d[0][0] + d[0][1]
		else:
			now += d[0][1]
		d.popleft()
		while ans[j] != 0:
			j += 1
		ans[j] = now
		j += 1
	if len(d) == b:
		ans[i] = -1
	else:
		d.append(t)
while len(d) != 0:
	if d[0][0] > now:
		now = d[0][0] + d[0][1]
	else:
		now += d[0][1]
	d.popleft()
	while ans[j] != 0:
		j += 1
	ans[j] = now
	j += 1
print(*ans)


from collections import deque
(n, b) = map(int, input().split())
query = {}
tm = []
que = deque()
ans = {}
for i in range(n):
	(u, v) = map(int, input().split())
	query[u] = v
	tm.append(u)
et = 0
for ti in tm:
	while ti > et and len(que) > 0:
		cur = que.popleft()
		et += query[cur]
		ans[cur] = et
	if ti > et:
		et = ti + query[ti]
		ans[ti] = et
	elif ti == et:
		if len(que) > 0:
			cur = que.popleft()
			et = ti + query[cur]
			ans[cur] = et
		que.append(ti)
	elif len(que) >= b:
		ans[ti] = -1
	else:
		que.append(ti)
while len(que) > 0:
	cur = que.popleft()
	et += query[cur]
	ans[cur] = et
outs = ''
space = False
for ti in tm:
	if space:
		outs += ' '
	else:
		space = True
	outs += str(ans[ti])
print(outs)


from queue import Queue
(n, m) = map(int, input().split())
a = []
ans = []
for i in range(n):
	a.append(tuple(list(map(int, input().split())) + [i]))
	ans.append(-1)
t = -1
q = Queue()
for i in range(n):
	while not q.empty() and t <= a[i][0]:
		next_task = q.get()
		t += next_task[1]
		ans[next_task[2]] = t
	if t > a[i][0]:
		if q.qsize() < m:
			q.put(a[i])
		else:
			continue
	elif not q.empty():
		q.put(a[i])
	else:
		t = max(a[i][0], t) + a[i][1]
		ans[i] = t
while not q.empty():
	next_task = q.get()
	t += next_task[1]
	ans[next_task[2]] = t
for i in range(n):
	print(ans[i], end='\n' if i == n - 1 else ' ')


import sys
input = sys.stdin.readline
q = []
processing = 0
(n, b) = map(int, input().split())
for _ in range(n):
	(t, d) = map(int, input().split())
	while len(q) != 0 and q[0] <= t:
		q.pop(0)
	if len(q) <= b:
		processing = max(processing, t) + d
		print(processing, end=' ')
		q.append(processing)
	else:
		print(-1, end=' ')


import sys
import collections
(n, queue_size) = map(int, input().split())
results = [-1 for _ in range(n)]
next_server_free_time = 1
queue = collections.deque()
for (idx, line) in enumerate(sys.stdin):
	(t, d) = map(int, line.split())
	while queue and next_server_free_time <= t:
		(idx1, d1) = queue.popleft()
		next_server_free_time += d1
		results[idx1] = next_server_free_time
	if next_server_free_time <= t:
		results[idx] = t + d
		next_server_free_time = t + d
	elif len(queue) < queue_size:
		queue.append((idx, d))
while queue:
	(idx, d) = queue.popleft()
	next_server_free_time += d
	results[idx] = next_server_free_time
print(' '.join(map(str, results)))


from sys import maxsize as m
from itertools import product as P

class Solution:

	def bazinga(self, N, p):
		pass

def __starting_point():
	(n, b) = list(map(int, input().split(' ')))
	(ct, pt, lpt, cb) = (0, 0, [], 0)
	result = []
	for i in range(n):
		(ti, di) = list(map(int, input().split()))
		res = 0
		if pt == 0:
			pt += ti + di
			lpt += [pt]
			res = pt
		elif ti < lpt[0]:
			if cb < b:
				pt += di
				lpt += [pt]
				res = pt
				cb += 1
			elif cb >= b:
				res = -1
		elif ti >= lpt[0]:
			if ti > lpt[-1]:
				pt += abs(lpt[-1] - ti) + di
			else:
				pt += di
			lpt += [pt]
			res = pt
			cb += 1
			while ti >= lpt[0]:
				if len(lpt) == 1:
					break
				lpt.pop(0)
				if cb > 0:
					cb -= 1
		result += (str(res),)
	print(' '.join(result))
__starting_point()


def main():
	(n, b) = map(int, input().split())

	def endgen():
		res = [0]
		q = 0
		for _ in range(n):
			(t, d) = map(int, input().split())
			res.append(t + d if t > res[-1] else res[-1] + d)
			while res[q] <= t:
				q += 1
			if len(res) - q - 1 > b:
				res.pop()
				yield '-1'
			else:
				yield str(res[-1])
	print(' '.join(endgen()))
main()


import queue
(n, b) = map(int, input().split())
queries = []
for i in range(n):
	(ti, di) = map(int, input().split())
	queries.append((ti, di))
result = [0] * n
q = queue.Queue()
q.put(0)
time = queries[0][0]
i = 1
while q.qsize() > 0:
	process = q.get()
	finish_time = max(time, queries[process][0]) + queries[process][1]
	time = finish_time
	result[process] = finish_time
	while i < n and queries[i][0] < time:
		if q.qsize() < b:
			q.put(i)
		else:
			result[i] = -1
		i += 1
	if i < n and q.qsize() == 0:
		q.put(i)
		i += 1
for x in result:
	print(x, end=' ')


(n, b) = map(int, input().split())
finish = [0] * n
t = []
d = []
for _ in range(n):
	i = input().split()
	t.append(int(i[0]))
	d.append(int(i[1]))
current = t[0]
q = []
for i in range(n):
	if q != []:
		current = max(current, t[q[0]])
	while q != [] and current + d[q[0]] <= t[i]:
		j = q.pop(0)
		current = max(current, t[j])
		current += d[j]
		finish[j] = current
	if len(q) <= b:
		q.append(i)
	else:
		finish[i] = -1
for i in q:
	current = max(current, t[i])
	current += d[i]
	finish[i] = current
print(' '.join([str(i) for i in finish]))


(n, b) = [int(item) for item in input().split()]
queue = []
for i in range(n):
	(ti, di) = [int(item) for item in input().split()]
	while len(queue) > 0 and queue[0] <= ti:
		queue.pop(0)
	if len(queue) - 1 == b:
		print(-1, end=' ')
		continue
	if not queue:
		queue.append(ti + di)
	else:
		queue.append(queue[-1] + di)
	print(queue[-1], end=' ')


import queue

class Scanner:
	import sys

	def __init__(self, istream=sys.stdin):
		self.tokenizer = Scanner.__tokenizer__(istream)

	def __tokenizer__(istream):
		for line in istream:
			for token in line.strip().split():
				yield token
		while True:
			yield None

	def next(self, type=str, rep=1):
		if rep == 1:
			return type(self.tokenizer.__next__())
		return [type(self.tokenizer.__next__()) for i in range(rep)]
sc = Scanner()
(n, b) = sc.next(int, 2)
q = queue.Queue()
processing = 0
for _ in range(n):
	(t, d) = sc.next(int, 2)
	while not q.empty() and q.queue[0] <= t:
		q.get()
	if q.qsize() <= b:
		processing = max(processing, t) + d
		print(processing, end=' ')
		q.put(processing)
	else:
		print(-1, end=' ')


import collections
nb = list(map(int, input().split()))
n = nb[0]
b = nb[1]
queries = collections.deque()
for i in range(n):
	td = list(map(int, input().split()))
	queries.append((td[0], td[1], i))
answer = [0] * n
processed = []
queue = collections.deque()
next_available = 0
i = 0
cnt = 0
while cnt != n:
	if not queue:
		(start, cost, i) = queries.popleft()
		queue.append((start, cost, i))
		continue
	else:
		(first_in_line_start, first_in_line_cost, cur_i) = queue.popleft()
		next_available = max(next_available, first_in_line_start) + first_in_line_cost
		answer[cur_i] = next_available
		cnt += 1
		while queries and queries[0][0] < next_available:
			if len(queue) >= b:
				(f1, f2, cur_i) = queries.popleft()
				answer[cur_i] = -1
				cnt += 1
			else:
				queue.append(queries.popleft())
print(*answer)


(n, b) = map(int, input().split())
queries = []
for _ in range(n):
	(t, d) = map(int, input().split())
	queries.append((t, d))
result = [0] * n
queue = []
n_queue = b + 1
process = []
for i in range(n):
	if len(queue) != 0 and queries[i][0] >= queue[0]:
		queue.pop(0)
	if len(queue) == 0:
		finish_time = queries[i][0] + queries[i][1]
		queue.append(finish_time)
		result[i] = finish_time
	elif len(queue) < n_queue:
		finish_time = max(queue[-1], queries[i][0]) + queries[i][1]
		queue.append(finish_time)
		result[i] = finish_time
	else:
		result[i] = -1
print(*result)


from collections import deque
(n, b) = map(int, input().split())
q = deque()
ans = []
for i in range(n):
	(ti, di) = map(int, input().split())
	while q and ti >= q[0]:
		q.popleft()
	if len(q) > b:
		ans.append(-1)
	elif q:
		ans.append(q[-1] + di)
		q.append(q[-1] + di)
	else:
		ans.append(ti + di)
		q.append(ti + di)
print(*ans)


import queue

class Query:

	def __init__(self, t, d, res=0):
		self.t = t
		self.d = d
(n, b) = map(int, input().split())
Query_q = []
for i in range(n):
	(tmp1, tmp2) = map(int, input().split())
	new_q = Query(tmp1, tmp2)
	Query_q.append(new_q)
res = [0] * n
cur_query = queue.Queue()
processing_end = 0
for i in range(n):
	while not cur_query.empty() and cur_query.queue[0] <= Query_q[i].t:
		cur_query.get()
	if cur_query.empty():
		processing_end = Query_q[i].t
	if cur_query.qsize() <= b:
		processing_end += Query_q[i].d
		res[i] = processing_end
		cur_query.put(res[i])
	else:
		res[i] = -1
for i in range(n):
	print(res[i], end=' ')


import queue

class Query:

	def __init__(self, t, d):
		self.t = t
		self.d = d
(n, b) = map(int, input().split())
a = []
for i in range(n):
	(t, d) = map(int, input().split())
	a.append(Query(t, d))
q = queue.Queue()
rejected_q = queue.Queue()
i = 0
while q.qsize() < b and i < n:
	q.put(a[i])
	i += 1
cur_time = a[0].t
while not q.empty() or not rejected_q.empty():
	if not q.empty():
		q_time = q.queue[0].t
	else:
		q_time = 10 ** 9 + 5
	if not rejected_q.empty():
		rejected_time = rejected_q.queue[0].t
	else:
		rejected_time = 10 ** 9 + 5
	if q_time < rejected_time:
		print(max(cur_time, q.queue[0].t) + q.queue[0].d, end=' ')
	else:
		print(-1, end=' ')
		rejected_q.get()
		continue
	if not q.empty():
		cur_time = max(cur_time, q.queue[0].t)
		cur_time += q.queue[0].d
		q.get()
	if i < n:
		q.put(a[i])
		i += 1
	while i < n:
		if a[i].t < cur_time:
			rejected_q.put(a[i])
			i += 1
		else:
			break


(n, maxq) = map(int, input().split())
from collections import deque
mess = []
queue = deque()
for i in range(n):
	(time, duration) = map(int, input().split())
	while queue and queue[0] <= time:
		queue.popleft()
	if not queue:
		queue.append(time + duration)
		mess.append(time + duration)
		continue
	elif len(queue) <= maxq:
		queue.append(queue[-1] + duration)
		mess.append(queue[-1])
	else:
		mess.append(-1)
print(' '.join(map(str, mess)))


import queue
import sys
input = sys.stdin.readline
(n, b) = map(int, input().split())
q = queue.Queue()
backOfQueue = 0
for i in range(n):
	(t, d) = map(int, input().split())
	while not q.empty() and q.queue[0] <= t:
		q.get()
	if q.qsize() <= b:
		if q.qsize() == 0:
			backOfQueue = t + d
		else:
			backOfQueue += d
		q.put(backOfQueue)
		print(backOfQueue, end=' ')
	else:
		print('-1', end=' ')


(n, b) = map(int, input().split())
l = [tuple(map(int, input().split())) for i in range(n)]
ch = [0]
ans = []
bd = [0] * (n + 1)
po = ma = 0
for i in range(n):
	(t, d) = l[i]
	bd[i] = bd[i - 1]
	ch += [max(ma, t) + d]
	while ch[po] <= t:
		po += 1
	if i - po - (bd[i - 1] - bd[po - 1]) == b:
		bd[i] += 1
		ch[-1] = -1
	if ch[-1] > ma:
		ma = ch[-1]
	ans += [str(ch[-1])]
print(' '.join(ans))


class Query:

	def __init__(self, t, d, f):
		self.t = t
		self.d = d
		self.f = f
queue = []
queries = []
(n, b) = map(int, input().split())
for i in range(n):
	(t, d) = map(int, input().split())
	query = Query(t, d, 0)
	queries.append(query)
query = queries[0]
t = query.t + query.d
query.f = t
queue.append(t)
for i in range(1, n, 1):
	while len(queue) > 0 and queries[i].t >= queue[0]:
		queue.pop(0)
	if t <= queries[i].t:
		t = queries[i].t + queries[i].d
		queries[i].f = t
		queue.append(t)
	elif len(queue) > b:
		queries[i].f = -1
	else:
		t += queries[i].d
		queries[i].f = t
		queue.append(t)
for query in queries:
	print('{0}'.format(query.f), end=' ')


from queue import Queue

def main():
	(n, max_size) = map(int, input().split())
	queue = Queue()
	query = list()
	for _ in range(n):
		(start, process) = map(int, input().split())
		query.append([start, process, 0])
	query[0][2] = query[0][0] + query[0][1]
	queue.put(query[0][2])
	for i in range(1, n):
		while not queue.empty() and query[i][0] >= queue.queue[0]:
			queue.get()
		if queue.empty() or query[i][0] >= queue.queue[queue.qsize() - 1]:
			query[i][2] = query[i][0] + query[i][1]
			queue.put(query[i][2])
		elif queue.qsize() > max_size:
			query[i][2] = -1
		else:
			query[i][2] = query[i][1] + queue.queue[queue.qsize() - 1]
			queue.put(query[i][2])
	for value in query:
		print(value[2], end=' ')
main()


from collections import deque
while True:
	try:
		(n, max_queue_lenth) = map(int, input().split())
	except EOFError:
		break
	queue = deque()
	responses = []
	for i in range(n):
		(time, duration) = tuple(map(int, input().split()))
		while queue and queue[0] <= time:
			queue.popleft()
		if not queue:
			queue.append(time + duration)
			responses.append(time + duration)
			continue
		elif len(queue) <= max_queue_lenth:
			queue.append(queue[-1] + duration)
			responses.append(queue[-1])
		else:
			responses.append(-1)
	print(' '.join(map(str, responses)))