There is an infinitely long street that runs west to east, which we consider as a number line.
There are N roadworks scheduled on this street.
The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.
Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point.
Find the distance each of the Q people will walk.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N, Q \leq 2 \times 10^5
 - 0 \leq S_i < T_i \leq 10^9
 - 1 \leq X_i \leq 10^9
 - 0 \leq D_1 < D_2 < ... < D_Q \leq 10^9
 - If i \neq j and X_i = X_j, the intervals [S_i, T_i) and [S_j, T_j) do not overlap.

-----Input-----
Input is given from Standard Input in the following format:
N Q
S_1 T_1 X_1
:
S_N T_N X_N
D_1
:
D_Q

-----Output-----
Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever.

-----Sample Input-----
4 6
1 3 2
7 13 10
18 20 13
3 4 2
0
1
2
3
5
8

-----Sample Output-----
2
2
10
-1
13
-1

The first person starts coordinate 0 at time 0 and stops walking at coordinate 2 when reaching a point blocked by the first roadwork at time 2.
The second person starts coordinate 0 at time 1 and reaches coordinate 2 at time 3. The first roadwork has ended, but the fourth roadwork has begun, so this person also stops walking at coordinate 2.
The fourth and sixth persons encounter no roadworks while walking, so they walk forever. The output for these cases is -1.

Difficulty: MEDIUM

Solutions:
from bisect import bisect_left, bisect_right
(N, Q) = map(int, input().split())
STX = [[int(i) for i in input().split()] for _ in range(N)]
D = [int(input()) for _ in range(Q)]
STX.sort(key=lambda x: x[2])
ans = [-1] * Q
skip = [-1] * Q
for (S, T, X) in STX:
	left = bisect_left(D, S - X)
	right = bisect_right(D, T - X - 1)
	while left < right:
		if skip[left] < 0:
			skip[left] = right
			ans[left] = X
			left += 1
		else:
			left = skip[left]
print(*ans, sep='\n')


import sys
input = sys.stdin.readline
from bisect import bisect_left
(n, q) = map(int, input().split())
STX = [tuple(map(int, input().split())) for _ in range(n)]
STX.sort(key=lambda x: x[2])
D = [int(input()) for _ in range(q)]
Ans = [-1] * q
Jump = [-1] * q
for (s, t, x) in STX:
	l = bisect_left(D, s - x)
	r = bisect_left(D, t - x)
	while l < r:
		s = Jump[l]
		if s == -1:
			Ans[l] = x
			Jump[l] = r
			l += 1
		else:
			l = s
print(*Ans, sep='\n')


from bisect import bisect_left
from operator import itemgetter
(N, Q) = map(int, input().split(' '))
check_points = [tuple(map(int, input().split(' '))) for _ in range(N)]
querys = [int(input()) for _ in range(Q)]
time = [-1] * Q
jump = [-1] * Q
check_points = sorted(check_points, key=itemgetter(2))
b_left = bisect_left
for line in check_points:
	(s, f, x) = line
	start = s - x
	end = f - x
	left = b_left(querys, start)
	right = b_left(querys, end)
	while left < right:
		if time[left] == -1:
			time[left] = x
			jump[left] = right
			left += 1
		else:
			left = jump[left]
for t in time:
	print(t)


import bisect
(N, Q) = (int(x) for x in input().split())
stop_arr = [tuple(map(int, input().split())) for _ in range(N)]
Q_arr = [int(input()) for _ in range(Q)]
stop_arr_ind = list(range(N))
stop_arr_ind.sort(key=lambda x: stop_arr[x][2])
ans_arr = [-1] * Q
skip_arr = [-1] * (Q + 1)

def update_skip(skip_arr, x):
	if skip_arr[x] == -1:
		return x
	x_dest = update_skip(skip_arr, skip_arr[x])
	skip_arr[x] = x_dest
	return x_dest
for i in stop_arr_ind:
	(s, t, x) = stop_arr[i]
	q_start = bisect.bisect_left(Q_arr, s - x)
	q_stop = bisect.bisect_left(Q_arr, t - x)
	l = q_start
	while l < q_stop:
		if skip_arr[l] == -1:
			skip_arr[l] = q_stop
			ans_arr[l] = x
			l += 1
		else:
			l = update_skip(skip_arr, l)
print(*ans_arr, sep='\n')


from bisect import bisect_left
(N, Q) = map(int, input().split())
consts = []
for _ in range(N):
	(s, t, x) = map(int, input().split())
	consts.append((x, s, t))
consts.sort()
D = [int(input()) for _ in range(Q)]
ans = [-1] * Q
jump = [-1] * Q
for (x, s, t) in consts:
	left = bisect_left(D, s - x)
	right = bisect_left(D, t - x)
	while left < right:
		if jump[left] == -1:
			ans[left] = x
			jump[left] = right
			left += 1
		else:
			left = jump[left]
print(*ans, sep='\n')


import heapq

def main():
	(N, Q) = list(map(int, input().split()))
	STX = tuple((list(map(int, input().split())) for _ in range(N)))
	D = tuple([int(input()) for _ in range(Q)])
	L = []
	for (s, t, x) in STX:
		L.append((x, s - x, t - x))
	L.sort(key=lambda x: x[1])
	q = []
	cnt = 0
	push = heapq.heappush
	pop = heapq.heappop
	t = []
	for i in range(Q):
		while cnt < len(L) and D[i] >= L[cnt][1]:
			if t != []:
				push(q, t)
				t = []
			push(q, L[cnt])
			cnt += 1
		if t != [] and t[2] > D[i]:
			print(t[0])
		else:
			while q != []:
				t = pop(q)
				if t[2] > D[i]:
					print(t[0])
					break
			else:
				t = []
				print(-1)
main()


import sys
from heapq import *
input = sys.stdin.readline
(n, Q) = [int(i) for i in input().split()]
stx = [[0] * 3 for _ in range(n)]
for j in range(n):
	a = [int(i) for i in input().split()]
	stx[j] = [a[0] - a[2], a[1] - a[2], a[2]]
q = [int(input()) for i in range(Q)]
stx.sort()
xt = []
pt = 0
for d in q:
	while pt < n and stx[pt][0] <= d:
		heappush(xt, (stx[pt][2], stx[pt][1]))
		pt += 1
	while xt and xt[0][1] <= d:
		heappop(xt)
	if xt:
		print(xt[0][0])
	else:
		print(-1)


import bisect
import sys
sys.setrecursionlimit(10000)
INF = float('inf')
(N, Q) = list(map(int, next(sys.stdin).split()))
STX = [list(map(int, next(sys.stdin).split())) for _ in range(N)]
D = [int(next(sys.stdin)) for _ in range(Q)]
ans = [-1] * Q
nexts = [-1] * Q
for (s, t, x) in sorted(STX, key=lambda stx: (stx[2], stx[1])):
	lo = max(0, bisect.bisect_left(D, s - x))
	hi = min(len(D), bisect.bisect_left(D, t - x))
	p = lo
	while p < hi:
		if nexts[p] == -1:
			ans[p] = x
			nexts[p] = hi
			p += 1
		else:
			prev = p
			p = nexts[p]
			nexts[prev] = hi
print('\n'.join(map(str, ans)))


from bisect import bisect_left
import sys
input = sys.stdin.readline

class UnionFind:

	def __init__(self, n):
		self.n = n
		self.parents = [-1] * n

	def find(self, x):
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return
		if self.parents[x] > self.parents[y]:
			(x, y) = (y, x)
		self.parents[x] += self.parents[y]
		self.parents[y] = x

	def same(self, x, y):
		return self.find(x) == self.find(y)

def main():
	(N, Q) = list(map(int, input().split()))
	kouji = [list(map(int, input().split())) for _ in range(N)]
	D = [int(input()) for _ in range(Q)]
	ans = [-1] * Q
	nxt = [i + 1 for i in range(Q)]
	uf = UnionFind(Q)
	kouji.sort(key=lambda x: x[2])
	for i in range(N):
		(S, T, X) = kouji[i]
		L = S - X
		R = T - X - 1
		L_idx = bisect_left(D, L)
		R_idx = bisect_left(D, R + 1)
		p = L_idx
		while p < R_idx:
			if ans[p] == -1:
				ans[p] = X
				uf.union(L_idx, p)
				nxt[p] = R_idx
				p += 1
			else:
				par = uf.find(p)
				p = nxt[par]
				uf.union(L_idx, par)
				par = uf.find(par)
				if nxt[par] < R_idx:
					nxt[par] = R_idx
				if nxt[par] < p:
					nxt[par] = p
	for i in range(Q):
		print(ans[i])

def __starting_point():
	main()
__starting_point()


import sys
import bisect
input = sys.stdin.readline
(N, Q) = map(int, input().split(' '))
construction = [list(map(int, input().split(' '))) for _ in range(N)]
D = [int(input()) for _ in range(Q)]
construction = sorted(construction, key=lambda x: x[2])
dist = [-1] * Q
jump = [-1] * Q
indices = list(range(Q))
for (s, t, x) in construction:
	i1 = bisect.bisect_left(D, s - x)
	i2 = bisect.bisect_left(D, t - x)
	i = i1
	while i < i2:
		k = jump[i]
		if k != -1:
			i = k
		else:
			jump[i] = i2
			dist[i] = x
			i += 1
for d in dist:
	print(d)


import sys
input = sys.stdin.readline
from bisect import bisect_left
(N, Q) = map(int, input().split())
W = [tuple(map(int, input().split())) for _ in range(N)]
W.sort(key=lambda x: x[2])
D = [int(input()) for _ in range(Q)]
ans = [-1] * Q
skip = [-1] * Q
for (s, t, x) in W:
	l = bisect_left(D, s - x)
	r = bisect_left(D, t - x)
	while l < r:
		if skip[l] == -1:
			ans[l] = x
			skip[l] = r
			l += 1
		else:
			l = skip[l]
print(*ans, sep='\n')


import sys
input = sys.stdin.readline
INF = 1 << 31
from bisect import bisect_left

def main():
	(N, Q) = map(int, input().split())
	roadwork = [tuple(map(int, input().split())) for _ in range(N)]
	roadwork.sort(key=lambda x: x[2])
	D = [int(input()) for _ in range(Q)]
	ans = [-1] * Q
	skip = [-1] * Q
	for (s, t, x) in roadwork:
		L = bisect_left(D, s - x)
		R = bisect_left(D, t - x)
		while L < R:
			if skip[L] == -1:
				ans[L] = x
				skip[L] = R
				L += 1
			else:
				L = skip[L]
	print('\n'.join(map(str, ans)))

def __starting_point():
	main()
__starting_point()


import sys
from bisect import bisect_left
input = sys.stdin.readline
(N, Q) = map(int, input().split())
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for _ in range(Q)]
STX = sorted(STX, key=lambda x: x[2])
MASK = [-1] * Q
ANS = [-1] * Q
for (s, t, x) in STX:
	s2 = s - x
	t2 = t - x
	start = bisect_left(D, s2)
	end = bisect_left(D, t2, lo=start)
	while start < end:
		if -1 == MASK[start]:
			ANS[start] = x
			MASK[start] = end
			start += 1
		else:
			start = MASK[start]
print(*ANS, sep='\n')


import sys
from bisect import bisect_left
(N, Q) = map(int, input().split())
STX = [None] * N
for i in range(N):
	(s, t, x) = map(int, input().split())
	STX[i] = [x, s, t]
STX.sort()
Dn = [None] * (Q + 1)
for i in range(Q):
	Dn[i] = int(input())
Dn[Q] = 10 ** 10
ans = [-1] * Q
skip = [-1] * Q
for (x, s, t) in STX:
	ss = bisect_left(Dn, s - x)
	tt = bisect_left(Dn, t - x)
	while ss < tt:
		sk = skip[ss]
		if sk == -1:
			ans[ss] = x
			skip[ss] = tt
			ss += 1
		else:
			ss = sk
print('\n'.join(map(str, ans)))


import sys
input = sys.stdin.readline

def bs(d, x):
	(l, r) = (0, len(d))
	while l < r:
		mid = (l + r) // 2
		if d[mid] < x:
			l = mid + 1
		else:
			r = mid
	return l

def main():
	(n, q) = map(int, input().split())
	stx = [tuple(map(int, input().split())) for _ in range(n)]
	stx = list(sorted(stx, key=lambda x: x[2]))
	dlist = [int(input()) for _ in range(q)]
	ans = [-1 for _ in range(q)]
	skip = [-1 for _ in range(q)]
	for (s, t, x) in stx:
		l = bs(dlist, s - x)
		r = bs(dlist, t - x)
		while l < r:
			if skip[l] == -1:
				ans[l] = x
				skip[l] = r
				l += 1
			else:
				l = skip[l]
	print(*ans, sep='\n')
main()


from bisect import bisect_left
from operator import itemgetter
(N, Q) = [int(i) for i in input().split()]
Construction = [tuple((int(i) for i in input().split())) for j in range(N)]
D = [int(input()) for _ in range(Q)]
ans = [-1] * Q
skip = [-1] * Q
Construction.sort(key=itemgetter(2))
for (s, t, x) in Construction:
	l = bisect_left(D, s - x)
	r = bisect_left(D, t - x)
	t = l
	while t < r:
		if skip[t] == -1:
			ans[t] = x
			skip[t] = r
			t += 1
		else:
			t = skip[t]
print(*ans, sep='\n')


import sys
input = sys.stdin.readline
from bisect import bisect_left
(n, q) = map(int, input().split())
stop = []
for i in range(n):
	(s, t, x) = map(int, input().split())
	stop.append((s, t, x))
stop.sort(key=lambda x: x[2])
d = [int(input()) for i in range(q)]
R = [-1] * q
ans = [-1] * q
for (s, t, x) in stop:
	l = bisect_left(d, s - x)
	r = bisect_left(d, t - x)
	while l < r:
		if R[l] == -1:
			ans[l] = x
			R[l] = r
			l += 1
		else:
			l = R[l]
for x in ans:
	print(x)


import sys
import bisect
input = sys.stdin.readline
(N, Q) = map(int, input().split())
STX = [list(map(int, input().split())) for _ in range(N)]
STX = sorted(STX, key=lambda x: x[2])
D = [int(input()) for _ in range(Q)]
ans = [-1] * Q
index = [-1] * Q
for (s, t, x) in STX:
	left = bisect.bisect_left(D, s - x - 0.5)
	right = bisect.bisect_left(D, t - x - 0.5)
	now = left
	while now < right:
		if index[now] == -1:
			ans[now] = x
			index[now] = right
			now += 1
		else:
			now = index[now]
for a in ans:
	print(a)


from heapq import heappush, heappop
import sys
input = sys.stdin.buffer.readline
(N, Q) = map(int, input().split())
E = []
for i in range(N):
	(s, t, x) = map(int, input().split())
	E.append((0, t - x, x, i))
	E.append((1, s - x, x, i))
D = [int(input()) for _ in range(Q)]
E.sort(key=lambda a: a[1], reverse=True)
ans = []
que = [(10 ** 18, -1)]
V = set()
for d in D:
	while E and E[-1][1] <= d:
		(f, _, x, i) = E.pop()
		if f == 0:
			V.add(i)
		else:
			heappush(que, (x, i))
	while que[0][1] in V:
		heappop(que)
	ans.append(que[0][0])
ans = [a if a < 10 ** 18 else -1 for a in ans]
print(*ans, sep='\n')


import bisect
import sys
input = sys.stdin.readline
(n, q) = map(int, input().split())
events = [list(map(int, input().split())) for _ in range(n)]
events.sort(key=lambda x: x[2])
departures = [int(input()) for _ in range(q)]
ans = ['-1'] * q
skip = [-1] * q
for (start, end, pos) in events:
	left = bisect.bisect_left(departures, start - pos)
	right = bisect.bisect_left(departures, end - pos)
	while left < right:
		if skip[left] == -1:
			ans[left] = str(pos)
			skip[left] = right
			left += 1
		else:
			left = skip[left]
print('\n'.join(ans))


from bisect import bisect_left
import sys
(n, Q) = [int(x) for x in sys.stdin.readline().split()]
stx = [[int(x) for x in sys.stdin.readline().split()] for i in range(n)]
q = [int(sys.stdin.readline()) for i in range(Q)]
stx.sort(key=lambda x: x[2])
ans = [-1 for i in range(Q)]
skip = [-1 for i in range(Q)]
for (s, t, x) in stx:
	begin = bisect_left(q, s - x)
	end = bisect_left(q, t - x)
	while begin < end:
		if skip[begin] == -1:
			ans[begin] = x
			skip[begin] = end
			begin += 1
		else:
			begin = skip[begin]
for e in ans:
	print(e)


import sys
from bisect import bisect_left

def main():
	input = sys.stdin.readline
	(N, Q) = map(int, input().split())
	closure = []
	for _ in range(N):
		(start, end, pos) = map(int, input().split())
		closure.append((pos, start, end))
	closure.sort()
	D = [int(input()) for _ in range(Q)]
	ans = [-1] * Q
	skip = [-1] * Q
	for (pos, start, end) in closure:
		left = bisect_left(D, start - pos)
		right = bisect_left(D, end - pos)
		while left < right:
			if skip[left] == -1:
				ans[left] = pos
				skip[left] = right
				left += 1
			else:
				left = skip[left]
	return ans
print(*main(), sep='\n')


def main():
	import bisect
	import sys
	input = sys.stdin.readline
	(n, q) = map(int, input().split())
	l = [list(map(int, input().split())) for i in range(n)]
	l = sorted(l, key=lambda x: x[2])
	d = [int(input()) for i in range(q)]
	ans = [-1] * q
	skip = [-1] * q
	for (s, t, x) in l:
		le = bisect.bisect_left(d, s - x)
		ri = bisect.bisect_left(d, t - x)
		while le < ri:
			if skip[le] == -1:
				ans[le] = x
				skip[le] = ri
				le += 1
			else:
				le = skip[le]
	for i in ans:
		print(i)
main()


import sys
from heapq import heappush, heappop
I = sys.stdin.readlines()
(N, Q) = map(int, I[0].split())
P = []
for i in range(1, N + 1):
	(s, t, x) = map(int, I[i].split())
	P.append((s - x, t - 1 - x, x))
P.sort()
q = []
cur = 0
cnt = 0
for i in range(N + 1, N + Q + 1):
	d = int(I[i])
	while cur < N and P[cur][0] <= d:
		(s, t, x) = P[cur]
		heappush(q, (x, t))
		cnt += 1
		cur += 1
	ans = -1
	while cnt:
		if d <= q[0][1]:
			ans = q[0][0]
			break
		else:
			heappop(q)
			cnt -= 1
	print(ans)


import math
import numpy as np
import decimal
import collections
import itertools
import sys
import random

class UnionFind:

	def __init__(self, n):
		self.n = n
		self.par = [-1 for i in range(self.n)]

	def find(self, x):
		if self.par[x] < 0:
			return x
		else:
			self.par[x] = self.find(self.par[x])
			return self.par[x]

	def unite(self, x, y):
		p = self.find(x)
		q = self.find(y)
		if p == q:
			return None
		if p > q:
			(p, q) = (q, p)
		self.par[p] += self.par[q]
		self.par[q] = p

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def size(self, x):
		return -self.par[self.find(x)]

def prime_numbers(x):
	if x < 2:
		return []
	prime_numbers = [i for i in range(x)]
	prime_numbers[1] = 0
	for prime_number in prime_numbers:
		if prime_number > math.sqrt(x):
			break
		if prime_number == 0:
			continue
		for composite_number in range(2 * prime_number, x, prime_number):
			prime_numbers[composite_number] = 0
	return [prime_number for prime_number in prime_numbers if prime_number != 0]

def is_prime(x):
	if x < 2:
		return False
	if x == 2 or x == 3 or x == 5:
		return True
	if x % 2 == 0 or x % 3 == 0 or x % 5 == 0:
		return False
	prime_number = 7
	difference = 4
	while prime_number <= math.sqrt(x):
		if x % prime_number == 0:
			return False
		prime_number += difference
		difference = 6 - difference
	return True

def prime_factorize(n):
	res = []
	while n % 2 == 0:
		res.append(2)
		n //= 2
	f = 3
	while f ** 2 <= n:
		if n % f == 0:
			res.append(f)
			n //= f
		else:
			f += 2
	if n != 1:
		res.append(n)
	return res
mod = 10 ** 9 + 7

class nCr:

	def __init__(self, n):
		self.n = n
		self.fa = [1] * (self.n + 1)
		self.fi = [1] * (self.n + 1)
		for i in range(1, self.n + 1):
			self.fa[i] = self.fa[i - 1] * i % mod
			self.fi[i] = pow(self.fa[i], mod - 2, mod)

	def comb(self, n, r):
		if n < r:
			return 0
		if n < 0 or r < 0:
			return 0
		return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod

def extgcd(a, b, d=0):
	g = a
	if b == 0:
		(x, y) = (1, 0)
	else:
		(x, y, g) = extgcd(b, a % b)
		(x, y) = (y, x - a // b * y)
	return (x, y, g)

class BinaryIndexedTree:

	def __init__(self, n):
		self.n = n
		self.BIT = [0] * (self.n + 1)

	def add(self, i, x):
		while i <= self.n:
			self.BIT[i] += x
			i += i & -i

	def query(self, i):
		res = 0
		while i > 0:
			res += self.BIT[i]
			i -= i & -i
		return res

class AssociativeArray:

	def __init__(self, q):
		self.dic = dict()
		self.q = q

	def solve(self):
		for i in range(self.q):
			Query = list(map(int, input().split()))
			if Query[0] == 0:
				(x, y, z) = Query
				self.dic[y] = z
			else:
				(x, y) = Query
				if y in self.dic:
					print(self.dic[y])
				else:
					print(0)

def floor_sum(n, m, a, b):
	res = 0
	if a >= m:
		res += (n - 1) * n * (a // m) // 2
		a %= m
	if b >= m:
		res += n * (b // m)
		b %= m
	y_max = (a * n + b) // m
	x_max = y_max * m - b
	if y_max == 0:
		return res
	res += y_max * (n + -x_max // a)
	res += floor_sum(y_max, a, m, (a - x_max % a) % a)
	return res

def z_algorithm(s):
	str_len = len(s)
	res = [0] * str_len
	res[str_len - 1] = str_len
	(i, j) = (1, 0)
	while i < str_len:
		while i + j < str_len and s[i + j] == s[j]:
			j += 1
		res[i] = j
		if j == 0:
			i += 1
			continue
		k = 1
		while i + k < str_len and j > res[k] + k:
			res[i + k] = res[k]
			k += 1
		i += k
		j -= k
	return res

class Manacher:

	def __init__(self, s):
		self.s = s

	def coustruct(self):
		(i, j) = (0, 0)
		s_len = len(self.s)
		res = [0] * s_len
		while i < s_len:
			while i - j >= 0 and i + j < s_len and (self.s[i - j] == self.s[i + j]):
				j += 1
			res[i] = j
			k = 1
			while i - k >= 0 and k + res[i - k] < j:
				k += 1
			i += k
			j -= k

def mod_sqrt(a, p):
	if a == 0:
		return 0
	if p == 2:
		return 1
	k = (p - 1) // 2
	if pow(a, k, p) != 1:
		return -1
	while True:
		n = random.randint(2, p - 1)
		r = (n ** 2 - a) % p
		if r == 0:
			return n
		if pow(r, k, p) == p - 1:
			break
	k += 1
	(w, x, y, z) = (n, 1, 1, 0)
	while k:
		if k % 2:
			(y, z) = (w * y + r * x * z, x * y + w * z)
		(w, x) = (w * w + r * x * x, 2 * w * x)
		w %= p
		x %= p
		y %= p
		z %= p
		k >>= 1
	return y
import bisect
(n, q) = map(int, input().split())
stx = [list(map(int, input().split())) for i in range(n)]
d = [int(input()) for i in range(q)]
stx.sort(key=lambda x: x[2])
ans = [-1 for i in range(q)]
lis = [-1 for i in range(q)]
for (s, t, x) in stx:
	l = bisect.bisect_left(d, s - x)
	r = bisect.bisect_left(d, t - x)
	while l < r:
		if lis[l] == -1:
			ans[l] = x
			lis[l] = r
			l += 1
		else:
			l = lis[l]
print(*ans, sep='\n')


from bisect import bisect_left as bl
(N, Q) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key=lambda x: x[2])
Y = [int(input()) for _ in range(Q)]
res = [-1] * Q
jump = [-1] * Q
for (s, t, x) in X:
	l = bl(Y, s - x)
	r = bl(Y, t - x)
	while l < r:
		s = jump[l]
		if s == -1:
			res[l] = x
			jump[l] = r
			l += 1
		else:
			l = s
print(*res, sep='\n')


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def read_int():
	return int(input())

def read_int_n():
	return list(map(int, input().split()))

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input().strip()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(N, Q, STX, D):
	E = []
	for (i, (s, t, x)) in enumerate(STX):
		E.append((s - x, 1, x, i))
		E.append((t - x, -1, x, i))
	E.sort(reverse=True)
	q = []
	done = set()
	ans = [-1] * Q
	for (j, d) in enumerate(D):
		while E and E[-1][0] <= d:
			(t, e, x, i) = E.pop()
			if e == 1:
				heapq.heappush(q, (x, i))
			else:
				done.add((x, i))
		while q and q[0] in done:
			done.remove(heapq.heappop(q))
		if q:
			ans[j] = q[0][0]
	for i in range(Q):
		print(ans[i])

def main():
	(N, Q) = read_int_n()
	STX = list((read_int_n() for _ in range(N)))
	D = list((read_int() for _ in range(Q)))
	slv(N, Q, STX, D)

def __starting_point():
	main()
__starting_point()


def main():
	from collections import deque, namedtuple
	from heapq import heappush, heappop
	from operator import attrgetter
	import sys
	input = sys.stdin.readline
	Event = namedtuple('Event', 'pos start end')
	UC = namedtuple('UC', 'pos end')
	(N, Q) = map(int, input().split())
	events = []
	for _ in range(N):
		(s, t, x) = map(int, input().split())
		e = Event(pos=x, start=s - x, end=t - x)
		events.append(e)
	events.sort(key=attrgetter('start'))
	events = deque(events)
	D = (int(input()) for _ in range(Q))
	ans = [-1] * Q
	h = []
	for (idx, d) in enumerate(D):
		while events and events[0].start <= d:
			e = events.popleft()
			heappush(h, UC(pos=e.pos, end=e.end))
		while h and h[0].end <= d:
			heappop(h)
		if h:
			ans[idx] = h[0].pos
	print(*ans, sep='\n')

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline
from heapq import *
(N, Q) = map(int, input().split())
X = []
for _ in range(N):
	(s, t, x) = map(int, input().split())
	X.append((s - x, t - x, x))
X = sorted(X, key=lambda x: x[0])
D = [int(input()) for _ in range(Q)]
i = 0
j = 0
A = []
B = []
C = []
for q in range(Q):
	while i < len(X) and D[q] >= X[i][0]:
		(a, b, x) = X[i]
		heappush(A, (x, b))
		heappush(B, (b, x))
		i += 1
	while len(B) and B[0][0] <= D[q]:
		(b, x) = heappop(B)
		heappush(C, (x, b))
	while len(C) and len(A) and (C[0][0] == A[0][0]):
		heappop(A)
		heappop(C)
	print(A[0][0] if A else -1)


import sys
from collections import deque, defaultdict
import copy
import bisect
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
(N, Q) = list(map(int, input().split()))
STX = []
D = []
for i in range(N):
	(S, T, X) = list(map(int, input().split()))
	STX.append((X, S, T))
STX = sorted(STX, key=lambda x: x[0])
for i in range(Q):
	D.append(int(input()))
skip = [-1] * Q
dist = [-1] * Q
for (X, S, T) in STX:
	s = S - X
	t = T - X - 1
	a = bisect.bisect_left(D, s)
	b = bisect.bisect_right(D, t)
	j = a
	while j < b:
		if skip[j] == -1:
			skip[j] = b
			dist[j] = X
			j += 1
		else:
			j = skip[j]
for i in range(Q):
	print(dist[i])


import bisect
(N, Q) = map(int, input().split())
road = []
pos = []
for _ in range(N):
	(s, t, x) = map(int, input().split())
	road.append((s - x, t - x, x))
for _ in range(Q):
	pos.append(int(input()))
road.sort(key=lambda x: x[2])
ans = [-1] * Q
ischecked = [-1] * Q
for (s, t, x) in road:
	l = bisect.bisect_left(pos, s)
	r = bisect.bisect_left(pos, t)
	while l < r:
		if ischecked[l] == -1:
			ischecked[l] = r
			ans[l] = x
			l += 1
		else:
			l = ischecked[l]
for i in range(Q):
	print(ans[i])


from bisect import bisect_left
(N, Q) = map(int, input().split())
STX = []
D = []
for _ in range(N):
	STX.append(list(map(int, input().split())))
for _ in range(Q):
	D.append(int(input()))
STX.sort(key=lambda x: x[2])
ans = [-1] * Q
skip = [-1] * Q
for (s, t, x) in STX:
	left = bisect_left(D, s - x)
	right = bisect_left(D, t - x)
	while left < right:
		if skip[left] == -1:
			ans[left] = x
			skip[left] = right
			left += 1
		else:
			left = skip[left]
for a in ans:
	print(a)


from heapq import heappush, heappop
import sys
input = sys.stdin.readline
(N, Q) = map(int, input().split())
E = []
for i in range(N):
	(s, t, x) = map(int, input().split())
	E.append((s - x, t - x, x))
D = []
for i in range(Q):
	d = int(input())
	D.append(d)
E = sorted(E)
que = []
(s, t, x) = E[0]
j = 1
(y, e) = (N, N)
ans = [-1] * Q
for (i, d) in enumerate(D):
	while j < N + 1 and s <= d:
		heappush(que, (x, t))
		(y, e) = que[0]
		if j < N:
			(s, t, x) = E[j]
		j += 1
	while que and e <= d:
		heappop(que)
		if que:
			(y, e) = que[0]
	if que:
		ans[i] = y
for i in ans:
	print(i)


from bisect import bisect_left
(N, Q) = map(int, input().split())
R = [tuple(map(int, input().split())) for i in range(N)]
R.sort(key=lambda r: r[2])
q = [int(input()) for _ in range(Q)]
ans = [-1] * Q
skip = [-1] * (Q + 1)
for (s, t, x) in R:
	l = bisect_left(q, s - x)
	r = bisect_left(q, t - x)
	while l < r:
		if skip[l] == -1:
			skip[l] = r
			ans[l] = x
			l += 1
		else:
			l = skip[l]
for i in range(Q):
	print(ans[i])


import bisect
import sys
input = sys.stdin.readline
(N, Q) = map(int, input().split())
STX = [tuple(map(int, input().split())) for i in range(N)]
STX.sort(key=lambda x: x[2])
ans = [-1] * Q
jump = [-1] * Q
D = [int(input()) for i in range(Q)]
for (s, t, x) in STX:
	l = bisect.bisect_left(D, s - x)
	r = bisect.bisect_left(D, t - x)
	while l < r:
		k = jump[l]
		if k == -1:
			ans[l] = x
			jump[l] = r
			l += 1
		else:
			l = k
for i in range(Q):
	print(ans[i])


import sys
input = sys.stdin.readline
(n, q) = map(int, input().split())
stx = [list(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]
stx = sorted(stx, key=lambda x: x[2])
ans = [-1 for _ in range(q)]
skip = [-1 for _ in range(q)]
from bisect import bisect_left
for (s, t, x) in stx:
	left = bisect_left(d, s - x)
	right = bisect_left(d, t - x)
	while left < right:
		if skip[left] == -1:
			ans[left] = x
			skip[left] = right
			left += 1
		else:
			left = skip[left]
print('\n'.join(map(str, ans)))


from bisect import bisect_left
(n, q) = map(int, input().split())
work = [list(map(int, input().split())) for _ in range(n)]
work = sorted(work, key=lambda x: x[2])
pos = [int(input()) for _ in range(q)]
ans = [-1] * q
checked = [-1] * q
for (s, t, x) in work:
	l = bisect_left(pos, s - x)
	r = bisect_left(pos, t - x)
	while l < r:
		if checked[l] == -1:
			checked[l] = r
			ans[l] = x
			l += 1
		else:
			l = checked[l]
for i in ans:
	print(i)


from bisect import bisect_left, bisect_right
from operator import itemgetter
import sys
input = sys.stdin.readline

def main():
	(N, Q) = map(int, input().split())
	constructions = [None] * N
	for i in range(N):
		(S, T, X) = map(int, input().split())
		constructions[i] = (S, T, X)
	constructions.sort(key=itemgetter(2))
	D = [int(input()) for _ in range(Q)]
	ans = [-1] * Q
	nxt = list(range(1, Q + 1))
	for (S, T, X) in constructions:
		l = bisect_left(D, S - X)
		r = bisect_right(D, T - X - 1)
		idx = l
		while idx < r:
			if ans[idx] == -1:
				ans[idx] = X
			nidx = nxt[idx]
			nxt[idx] = max(nxt[idx], r)
			idx = nidx
	for a in ans:
		print(a)
main()


from bisect import bisect_left

def solve(n, q, s, t, x, d):
	v = sorted(list(zip(s, t, x)), key=lambda _: _[2])
	res = [-1] * q
	jump = [-1] * q
	for (s, t, x) in v:
		l = bisect_left(d, s - x)
		r = bisect_left(d, t - x)
		while l < r:
			s = jump[l]
			if s == -1:
				res[l] = x
				jump[l] = r
				l += 1
			else:
				l = s
	return res
(n, q) = map(int, input().split())
s = [-1] * n
t = [-1] * n
x = [-1] * n
for i in range(n):
	(s[i], t[i], x[i]) = map(int, input().split())
d = [int(input()) for i in range(q)]
print(*solve(n, q, s, t, x, d), sep='\n')


import sys
from heapq import heappush, heappop
from collections import defaultdict
input = sys.stdin.readline
(num, person) = map(int, input().split())
arr = []
for i in range(num):
	(s, t, x) = map(int, input().split())
	arr.append((s - x - 0.5, 1, x, i))
	arr.append((t - x - 0.5, -1, x, i))
for i in range(person):
	d = int(input())
	arr.append((d,))
arr.sort()
heap = []
done = set()
for elem in arr:
	if len(elem) == 1:
		d = elem[0]
		while heap and heap[0][1] in done:
			heappop(heap)
		if heap:
			print(heap[0][0])
		else:
			print(-1)
		continue
	(time, kind, x, i) = elem
	if kind == 1:
		heappush(heap, (x, i))
	elif kind == -1:
		done.add(i)


import bisect as bs
(N, Q) = map(int, input().split())
E = []
for i in range(N):
	(s, t, x) = map(int, input().split())
	a = [s - x, t - x, x]
	E.append(a)
E.sort(key=lambda x: x[2])
D = []
for i in range(Q):
	D.append(int(input()))
ans = [-1] * Q
check = [-1] * Q
for e in E:
	l = bs.bisect_left(D, e[0])
	r = bs.bisect_left(D, e[1])
	while l < r:
		if check[l] == -1:
			ans[l] = e[2]
			check[l] = r
			l += 1
		else:
			l = check[l]
[print(i) for i in ans]


import bisect
import heapq
import sys
(N, Q) = [int(x) for x in sys.stdin.readline().split()]
hitos = []
ans = [-1 for _ in range(Q)]
queries = []
jump = ans[:]
queries = [[int(x) for x in sys.stdin.readline().split()] for i in range(N)]
hitos = [int(sys.stdin.readline()) for i in range(Q)]
queries.sort(key=lambda x: x[2])
for (l, r, x) in queries:
	lind = bisect.bisect_left(hitos, l - x - 0.5)
	rind = bisect.bisect_left(hitos, r - x - 0.5)
	while lind < rind:
		if ans[lind] == -1:
			ans[lind] = x
			jump[lind] = rind
			lind += 1
		else:
			lind = jump[lind]
for i in ans:
	print(i)


from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline
(N, Q) = map(int, input().split())
events = []
for iR in range(N):
	(S, T, X) = map(int, input().split())
	events.append((S - X, T - X, X))
events.sort()
iE = 0
anss = []
PQ = []
for _ in range(Q):
	D = int(input())
	while iE < N and events[iE][0] <= D:
		(tmSt, tmEn, x) = events[iE]
		heappush(PQ, (x, tmEn))
		iE += 1
	xMin = -1
	while PQ:
		(x, tmEn) = heappop(PQ)
		if tmEn > D:
			xMin = x
			heappush(PQ, (x, tmEn))
			break
	anss.append(xMin)
print('\n'.join(map(str, anss)))


from bisect import bisect_left
from operator import itemgetter
(n, q) = map(int, input().split())
stx = [tuple((int(x) for x in input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]
ans = [-1] * q
skip = [-1] * q
stx.sort(key=itemgetter(2))
for (s, t, x) in stx:
	L = bisect_left(d, s - x)
	R = bisect_left(d, t - x)
	while L < R:
		if skip[L] == -1:
			ans[L] = x
			skip[L] = R
			L += 1
		else:
			L = skip[L]
for x in ans:
	print(x)


def main():
	import sys
	input = sys.stdin.readline
	from bisect import bisect_left
	(N, Q) = map(int, input().split())
	c = []
	c_append = c.append
	for _ in range(N):
		(s, t, x) = map(int, input().split())
		c_append((x, s, t))
	c.sort()
	D = [int(input()) for _ in range(Q)]
	ans = [-1] * Q
	skip = [-1] * Q
	for (x, s, t) in c:
		left = bisect_left(D, s - x)
		right = bisect_left(D, t - x)
		while left < right:
			if skip[left] == -1:
				ans[left] = x
				skip[left] = right
				left += 1
			else:
				left = skip[left]
	print('\n'.join(map(str, ans)))
main()


import heapq
import sys
input = sys.stdin.readline
(N, Q) = map(int, input().split())
H = []
for i in range(N):
	(s, t, x) = map(int, input().split())
	H.append([s - x, t - x, x])
H.sort()
P = 0
q = []
heapq.heapify(q)
for i in range(Q):
	n = int(input())
	if P < N:
		while H[P][0] <= n:
			heapq.heappush(q, [H[P][2], H[P][0], H[P][1]])
			P += 1
			if P == N:
				break
	if len(q) > 0:
		while q[0][2] <= n:
			heapq.heappop(q)
			if len(q) == 0:
				break
	if len(q) == 0:
		print(-1)
	else:
		print(q[0][0])


from bisect import bisect_left

def main():
	(ConstNum, PersonNum) = map(int, input().split())
	S = []
	T = []
	X = []
	for i in range(ConstNum):
		(s, t, x) = map(int, input().split())
		S.append(s)
		T.append(t)
		X.append(x)
	DepartureTime = []
	for i in range(PersonNum):
		d = int(input())
		DepartureTime.append(d)
	XST = zip(X, S, T)
	XST = sorted(XST)
	res = [-1] * PersonNum
	stop = [-1] * PersonNum
	for (x, s, t) in XST:
		left_value = s - x
		right_value = t - x
		left_index = bisect_left(DepartureTime, left_value)
		right_index = bisect_left(DepartureTime, right_value)
		while left_index < right_index:
			if stop[left_index] == -1:
				res[left_index] = x
				stop[left_index] = right_index
				left_index += 1
			else:
				left_index = stop[left_index]
	for i in range(PersonNum):
		print(res[i])

def __starting_point():
	main()
__starting_point()


def main():
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 7)
	from collections import Counter, deque
	from itertools import combinations, permutations, accumulate, groupby, product
	from bisect import bisect_left, bisect_right
	from heapq import heapify, heappop, heappush
	import math
	(n, q) = map(int, input().split())
	l = []
	for _ in range(n):
		(s, t, x) = map(int, input().split())
		l.append((s, t, x))
	l.sort(key=lambda a: a[2])
	start = [int(input()) for _ in range(q)]
	skip = [-1] * q
	res = [-1] * q
	for (s, t, x) in l:
		left = bisect_left(start, s - x)
		right = bisect_left(start, t - x)
		while left < right:
			if skip[left] == -1:
				res[left] = x
				skip[left] = right
				left += 1
			else:
				left = skip[left]
	for i in res:
		print(i)

def __starting_point():
	main()
__starting_point()


from bisect import bisect_left as bisect
(N, Q) = map(int, input().split())
event = [tuple(map(int, input().split())) for i in range(N)]
D = [int(input()) for i in range(Q)]
event.sort(key=lambda x: x[2])
ans = [-1] * Q
neg = [-1] * Q
for (s, t, x) in event:
	l = bisect(D, s - x)
	r = bisect(D, t - x)
	t = l
	while t < r:
		if neg[t] == -1:
			ans[t] = x
			neg[t] = r
			t += 1
		else:
			t = neg[t]
for i in range(Q):
	print(ans[i])


import sys
from bisect import bisect_left
input = sys.stdin.readline
(n, q) = map(int, input().split())
stx = [tuple(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]
stx.sort(key=lambda x: x[2])
ans = [-1] * q
jump = [-1] * q
for (s, t, x) in stx:
	d_start = bisect_left(d, s - x)
	d_stop = bisect_left(d, t - x, lo=d_start)
	while d_start < d_stop:
		if jump[d_start] == -1:
			ans[d_start] = x
			jump[d_start] = d_stop
			d_start += 1
		else:
			d_start = jump[d_start]
for an in ans:
	print(an)


import sys
input = sys.stdin.readline

def N():
	return int(input())

def NM():
	return map(int, input().split())

def L():
	return list(NM())

def LN(n):
	return [N() for i in range(n)]

def LL(n):
	return [L() for i in range(n)]

def YesNo(x):
	print('Yes') if x == True else print('No')
(n, q) = NM()
l = []
for i in range(n):
	(s, t, x) = NM()
	l.append((s - x, t - x, x))
l.sort()
INF = float('inf')
l += [(INF, INF, INF)]
d = LN(q)
q = []
from heapq import heappush, heappop
j = 0
for i in d:
	while l[j][0] <= i:
		(s, t, x) = l[j]
		heappush(q, (x, t))
		j += 1
	if len(q) == 0:
		print(-1)
	else:
		while q:
			(x, t) = heappop(q)
			if t > i:
				heappush(q, (x, t))
				print(x)
				break
		else:
			print(-1)


from bisect import bisect_left

def main():
	(N, Q) = map(int, input().split())
	W = [tuple(map(int, input().split())) for _ in range(N)]
	W.sort(key=lambda x: x[2])
	D = [int(input()) for _ in range(Q)]
	ans = [-1] * Q
	skip = [-1] * Q
	for (s, t, x) in W:
		l = bisect_left(D, s - x)
		r = bisect_left(D, t - x)
		while l < r:
			if skip[l] == -1:
				ans[l] = x
				skip[l] = r
				l += 1
			else:
				l = skip[l]
	for a in ans:
		print(a)
main()


import bisect
(n, q) = map(int, input().split())
STX = []
for i in range(n):
	(s, t, x) = map(int, input().split())
	STX.append((s, t, x))
STX.sort(key=lambda _: _[2])
(S, T, X) = ([], [], [])
for stx in STX:
	(s, t, x) = stx
	S.append(s)
	T.append(t)
	X.append(x)
D = [int(input()) for j in range(q)]
A = [-1 for j in range(q)]
B = [-1 for j in range(q)]
for i in range(n):
	l = bisect.bisect_left(D, S[i] - X[i])
	r = bisect.bisect_left(D, T[i] - X[i])
	while l < r:
		if B[l] == -1:
			A[l] = X[i]
			B[l] = r
			l += 1
		else:
			l = B[l]
print(*A, sep='\n')


import bisect
(n, q) = list(map(int, input().split()))
list_xst = []
for _ in range(n):
	(s, t, x) = list(map(int, input().split()))
	list_xst.append([x, s - x, t - x])
list_xst.sort(key=lambda l: l[0])
list_d = [int(input()) for _ in range(q)]
retn = [-1] * q
jmp = [-1] * q
for (x, s, t) in list_xst:
	i = bisect.bisect_left(list_d, s)
	tt = bisect.bisect_left(list_d, t)
	while i < tt:
		if jmp[i] != -1:
			i = jmp[i]
		else:
			retn[i] = x
			jmp[i] = tt
			i += 1
print(*retn, sep='\n')


import sys
input = sys.stdin.readline
from bisect import bisect_left
(n, q) = map(int, input().split())
road = [list(map(int, input().split())) for i in range(n)]
road.sort(key=lambda x: x[2])
start = [int(input()) for i in range(q)]
skip = [-1] * q
ans = [-1] * q
for (s, t, x) in road:
	left = bisect_left(start, s - x)
	right = bisect_left(start, t - x)
	while left < right:
		if skip[left] == -1:
			ans[left] = x
			skip[left] = right
			left += 1
		else:
			left = skip[left]
print(*ans, sep='\n')


import sys
from heapq import heappush, heappop
(n, q) = map(int, input().split())
a = sorted(((s - x, t - x, x) for _ in range(n) for (s, t, x) in (map(int, sys.stdin.readline().split()),)), reverse=True)
heap = []
ans = []
for i in range(q):
	d = int(input())
	while a and a[-1][0] <= d:
		e = a.pop()
		heappush(heap, (e[2], e[1]))
	while heap and heap[0][1] <= d:
		heappop(heap)
	if heap:
		ans.append(heap[0][0])
	else:
		ans.append(-1)
print(*ans, sep='\n')


import bisect
(N, Q) = (int(x) for x in input().split())
stop_arr = [tuple(map(int, input().split())) for _ in range(N)]
Q_arr = [int(input()) for _ in range(Q)]
stop_arr.sort(key=lambda x: x[2])
ans_arr = [-1] * Q
skip_arr = [-1] * (Q + 1)
for (s, t, x) in stop_arr:
	q_start = bisect.bisect_left(Q_arr, s - x)
	q_stop = bisect.bisect_left(Q_arr, t - x)
	l = q_start
	while l < q_stop:
		if skip_arr[l] == -1:
			skip_arr[l] = q_stop
			ans_arr[l] = x
			l += 1
		else:
			l = skip_arr[l]
print(*ans_arr, sep='\n')


from operator import itemgetter
from bisect import bisect_left

def main():
	(n, q) = list(map(int, input().split()))
	stops = []
	for _ in range(n):
		(s, t, x) = list(map(int, input().split()))
		stops.append((s, t, x))
	delay = []
	for i in range(q):
		delay.append(int(input()))
	stops = sorted(stops, key=itemgetter(2))
	delay = sorted(delay)
	result = [-1] * q
	skips = [-1] * q
	for (s, t, x) in stops:
		sx = bisect_left(delay, s - x)
		tx = bisect_left(delay, t - x)
		while sx < tx:
			if skips[sx] == -1:
				result[sx] = x
				skips[sx] = tx
				sx += 1
			else:
				sx = skips[sx]
	for r in result:
		print(r)
main()


import bisect
import sys
input = sys.stdin.readline
(N, Q) = map(int, input().split())
(S, T, X) = ([0] * N, [0] * N, [0] * N)
work = []
for i in range(N):
	(S[i], T[i], X[i]) = map(int, input().split())
	work.append((X[i], S[i] - X[i], T[i] - X[i]))
D = [int(input()) for _ in range(Q)]
work.sort()
ans = [-1] * Q
skip = [-1] * Q
for i in range(N):
	left = bisect.bisect_left(D, work[i][1])
	right = bisect.bisect_left(D, work[i][2])
	while left < right:
		if skip[left] == -1:
			skip[left] = right
			ans[left] = work[i][0]
			left += 1
		else:
			left = skip[left]
for i in ans:
	print(i)


import sys, heapq
input = sys.stdin.readline
(N, Q) = map(int, input().split())
event = []
for _ in range(N):
	(s, t, x) = map(int, input().split())
	event.append([s - x, t - x, x])
D = [int(input()) for _ in range(Q)]
event.sort()
closed = []
ei = 0
for d in D:
	while ei < N and event[ei][0] <= d:
		heapq.heappush(closed, (event[ei][2], event[ei][1]))
		ei += 1
	while closed and closed[0][1] <= d:
		heapq.heappop(closed)
	if closed:
		print(closed[0][0])
	else:
		print(-1)


import sys
input = sys.stdin.readline
from heapq import heappop, heappush
from bisect import bisect, bisect_left
(N, Q) = map(int, input().split())
table = []
for i in range(N):
	(s, t, x) = map(int, input().split())
	if t - 1 - x < 0:
		continue
	table.append((x, max(0, s - x), t - 1 - x))
H = []
D = [int(input()) for i in range(Q)]
for (x, a, b) in table:
	heappush(H, (bisect_left(D, a), bisect(D, b), x))
K = []
U = [10 ** 12] * Q
J = []
for i in range(Q):
	while len(H) > 0 and H[0][0] <= i:
		(a, b, x) = heappop(H)
		heappush(J, (x, a, b))
	while len(J) > 0 and J[0][2] <= i:
		(x, a, b) = heappop(J)
	if len(J) > 0:
		U[i] = min(U[i], J[0][0])
for i in range(Q):
	if U[i] == 10 ** 12:
		print(-1)
	else:
		print(U[i])


import sys
from heapq import *
input = sys.stdin.readline

def main():
	(n, q) = list(map(int, input().split()))
	key = []
	for i in range(n):
		(s, t, x) = list(map(int, input().split()))
		(l, r) = (max(0, s - x), max(0, t - x))
		key.append((l, 1, x))
		key.append((r, -1, x))
	for i in range(q):
		d = int(input())
		key.append((d, 2))
	key.sort()
	judge = []
	already = dict()
	for i in range(2 * n + q):
		k = key[i]
		if k[1] == -1:
			if k[2] in already:
				already[k[2]] += 1
			else:
				already[k[2]] = 1
		elif k[1] == 1:
			heappush(judge, k[2])
		else:
			while judge:
				if judge[0] in already and already[judge[0]] > 0:
					already[judge[0]] -= 1
					heappop(judge)
				else:
					break
			if judge:
				print(judge[0])
			else:
				print(-1)

def __starting_point():
	main()
__starting_point()


import sys
from heapq import heappush, heappop
input = sys.stdin.readline
data = []
(n, q) = map(int, input().split())
for i in range(n):
	(s, t, x) = map(int, input().split())
	data.append([s - x, t - x, x])
data.sort(key=lambda x: x[0])
d_index = 0
candidate_x = []
inf = float('inf')
data += [[inf, inf, inf]]
for i in range(q):
	d = int(input())
	while d >= data[d_index][0]:
		heappush(candidate_x, (data[d_index][2], data[d_index][1]))
		d_index += 1
	if len(candidate_x) == 0:
		print(-1)
	else:
		while candidate_x:
			(x, finish_t) = heappop(candidate_x)
			if finish_t > d:
				heappush(candidate_x, (x, finish_t))
				print(x)
				break
		else:
			print(-1)


import sys
from heapq import heappush, heappop
I = sys.stdin.readlines()
(N, Q) = map(int, I[0].split())
P = []
for i in range(1, N + 1):
	(s, t, x) = map(int, I[i].split())
	P.append((s - x, t - 1 - x, x))
P.sort()
INF = float('inf')
P.append((INF, INF, INF))
q = []
cur = 0
(s, t, x) = P[cur]
for i in range(N + 1, N + Q + 1):
	d = int(I[i])
	while s <= d:
		heappush(q, (x, t))
		cur += 1
		(s, t, x) = P[cur]
	ans = -1
	while len(q) > 0:
		(x1, t1) = q[0]
		if d <= t1:
			ans = x1
			break
		else:
			heappop(q)
	print(ans)


import sys
input = sys.stdin.readline
(N, Q) = map(int, input().split())
S = [None] * N
T = [None] * N
X = [None] * N
for i in range(N):
	(S[i], T[i], X[i]) = map(int, input().split())
D = [None] * Q
for i in range(Q):
	D[i] = int(input())
roadworks = [(x, s, t) for (x, s, t) in zip(X, S, T)]
roadworks = sorted(roadworks, key=lambda x: x[0])
walkers = D[:]
ans = [-1] * Q
skip = [-1] * Q
import bisect
for (x, s, t) in roadworks:
	left = bisect.bisect_left(walkers, s - x)
	right = bisect.bisect_left(walkers, t - x)
	i = left
	while i < right:
		if skip[i] == -1:
			ans[i] = x
			skip[i] = right
			i += 1
		else:
			i = skip[i]
for a in ans:
	print(a)


import sys
input = sys.stdin.readline
(N, Q) = list(map(int, input().split()))
events = [list(map(int, input().split())) for _ in range(N)]
D = [int(input()) for i in range(Q)]
ans = ['-1'] * Q
skip = [-1] * Q
events.sort(key=lambda x: x[2])
import bisect
for (S, T, X) in events:
	right = bisect.bisect_left(D, T - X)
	left = bisect.bisect_left(D, S - X)
	while left < right:
		if skip[left] == -1:
			ans[left] = str(X)
			skip[left] = right
			left += 1
		else:
			left = skip[left]
print('\n'.join(ans))


(n, q) = map(int, input().split())
import heapq
import sys
input = sys.stdin.readline
event = []
for _ in range(n):
	(s, t, x) = map(int, input().split())
	heapq.heappush(event, (s - x, t - x, x))
t = 0
now = []
for _ in range(q):
	d = int(input())
	if event:
		while event[0][0] <= d:
			tmp = heapq.heappop(event)
			heapq.heappush(now, (tmp[2], tmp[1]))
			if not event:
				break
	if now:
		while now[0][1] <= d:
			heapq.heappop(now)
			if not now:
				print(-1)
				break
		else:
			print(now[0][0])
	else:
		print(-1)


from heapq import heappush, heappop
import sys
readline = sys.stdin.readline
(N, Q) = map(int, readline().split())
ans = [None] * Q

def solve(readline=readline):
	qs = [0] * (N + 1)
	for i in range(N):
		(s, t, x) = map(int, readline().split())
		qs[i] = (s - x, t - x, x)
	qs[N] = (10 ** 10, 10 ** 10, 0)
	qs.sort()
	que = []
	D = [int(readline()) for i in range(Q)]
	j = 0
	it = iter(qs).__next__
	(s, t, x) = it()
	v = w = N
	for d in D:
		while j < N and s <= d:
			heappush(que, (x, t))
			(v, w) = que[0]
			(s, t, x) = it()
		while que and w <= d:
			heappop(que)
			if que:
				(v, w) = que[0]
		if que:
			yield ('%d\n' % v)
		else:
			yield '-1\n'
ans[:] = solve()
sys.stdout.writelines(ans)


import heapq
from collections import deque
(N, Q) = map(int, input().split())
H = [(0, 0, 0) for _ in range(N)]
for i in range(N):
	(s, t, x) = map(int, input().split())
	H[i] = (x - t + 1, x - s, x)
D = [(-int(input()), i) for i in range(Q)]
D.sort()
H.sort()
d = deque(H)
q = []
ANS = [0] * Q
for i in range(Q):
	(t, j) = D[i]
	while d:
		if d[0][0] <= t:
			(_, s, x) = d.popleft()
			heapq.heappush(q, (x, s))
		else:
			break
	while q:
		if q[0][1] >= t:
			break
		heapq.heappop(q)
	if not q:
		ANS[j] = -1
	else:
		ANS[j] = q[0][0]
for ans in ANS:
	print(ans)


import sys
import heapq
from collections import defaultdict
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
(N, Q) = map(int, input().split())
task = []
for _ in range(N):
	(s, t, x) = map(int, input().split())
	start = t - x
	end = s - x
	task.append((start, -1, x))
	task.append((end, 1, x))
task.sort(reverse=True)
cand = []
discard = defaultdict(int)
ans = []
for _ in range(Q):
	d = int(input())
	while task and task[-1][0] <= d:
		(_, flag, x) = task.pop()
		if flag == 1:
			heapq.heappush(cand, x)
		else:
			discard[x] += 1
	while cand:
		x = cand[0]
		if discard[x] > 0:
			heapq.heappop(cand)
			discard[x] -= 1
		else:
			break
	if cand:
		ans.append(cand[0])
	else:
		ans.append(-1)
print(*ans, sep='\n')


import sys
from bisect import *
input = sys.stdin.readline

def f(n, q):
	xst = []
	for i in range(n):
		(s, t, x) = map(int, input().split())
		xst.append([x, s - x, t - x])
	xst.sort()
	ds = []
	for i in range(q):
		d = int(input())
		ds.append(d)
	ans = [-1] * q
	jump = [-1] * q
	for (x, s, t) in xst:
		i = bisect_left(ds, s)
		fi = bisect_left(ds, t)
		while i < fi:
			if jump[i] != -1:
				i = jump[i]
			else:
				ans[i] = x
				jump[i] = fi
				i += 1
	print(*ans, sep='\n')
(n, q) = map(int, input().split())
f(n, q)


from bisect import bisect, bisect_left
import sys
input = sys.stdin.readline

def main():
	(n, q) = map(int, input().split())
	xst = []
	for i in range(n):
		(s, t, x) = map(int, input().split())
		xst.append([x, s - x, t - x])
	xst.sort()
	d = [None] * q
	for i in range(q):
		d[i] = int(input())
	ans = [-1] * q
	skip = [-1] * q
	for u in xst:
		(x, left, right) = u
		a = bisect_left(d, left)
		b = bisect_left(d, right)
		while a < b:
			if skip[a] == -1:
				ans[a] = x
				skip[a] = b
				a += 1
			else:
				a = skip[a]
	for u in ans:
		print(u)
main()


import sys
input = sys.stdin.readline
from collections import deque
from heapq import heappush, heappop
import re

def int_raw():
	return int(input())

def ss_raw():
	return input().split()

def ints_raw():
	return tuple(map(int, ss_raw()))

def main():
	(N, Q) = ints_raw()
	origST = []
	for idx in range(N):
		(S, T, X) = ints_raw()
		origST.append([S - X, T - X, X])
	Ds = [int(input()) for _ in range(Q)]
	origST.sort()
	stidx = 0
	cur_set = []
	for q in Ds:
		while stidx < len(origST):
			st = origST[stidx]
			if st[0] > q:
				break
			heappush(cur_set, (st[2], st[1]))
			stidx += 1
		while cur_set and cur_set[0][1] <= q:
			heappop(cur_set)
		if len(cur_set) == 0:
			print(-1)
		else:
			print(cur_set[0][0])
main()


from bisect import bisect_left
(n, q) = map(int, input().split())
stx = [list(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]
INF = 10 ** 9 + 1
stx.sort(key=lambda x: x[2])
nxt = [-1] * q
ans = [-1] * q
for (s, t, x) in stx:
	l = bisect_left(d, s - x)
	r = bisect_left(d, t - x)
	while l < r:
		if nxt[l] == -1:
			ans[l] = x
			nxt[l] = r
			l += 1
		else:
			l = nxt[l]
print(*ans, sep='\n')


from heapq import heappop as hpp, heappush as hp
import sys
(N, Q) = map(int, input().split())
stx = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
stx = [(s - x, t - x, x) for (s, t, x) in stx]
stx.sort(reverse=True)
D = [int(sys.stdin.readline()) for _ in range(Q)]
H = []
ans = [None] * Q
for (i, d) in enumerate(D):
	while stx and stx[-1][0] <= d:
		hp(H, stx.pop()[1:][::-1])
	while H and H[0][1] <= d:
		hpp(H)
	if not H:
		ans[i] = -1
	else:
		ans[i] = H[0][0]
for a in ans:
	print(a)


import sys
from heapq import *
input = sys.stdin.readline
(n, Q) = list(map(int, input().split()))
Y = []
for j in range(n):
	a = list(map(int, input().split()))
	Y.append([a[0] - a[2], a[1] - a[2], a[2]])
q = [int(input()) for i in range(Q)]
Y.sort()
X = []
p = 0
for d in q:
	while p < n and Y[p][0] <= d:
		heappush(X, (Y[p][2], Y[p][1]))
		p += 1
	while X and X[0][1] <= d:
		heappop(X)
	if X:
		print(X[0][0])
	else:
		print(-1)


import sys
import bisect
input = sys.stdin.readline
(n, q) = map(int, input().split())
cons = [list(map(int, input().split())) for _ in range(n)]
d = [int(input()) for _ in range(q)]
cons.sort(key=lambda x: x[2])
for i in range(n):
	cons[i][0] -= cons[i][2]
	cons[i][1] -= cons[i][2]
ans = [-1] * q
l = [-1] * q
for i in range(n):
	s = bisect.bisect_left(d, cons[i][0])
	t = bisect.bisect_left(d, cons[i][1])
	while s < t:
		if l[s] != -1:
			s = l[s]
		else:
			ans[s] = cons[i][2]
			l[s] = t
			s += 1
print(*ans, sep='\n')


from bisect import bisect_left
(n, Q) = list(map(int, input().split()))
stx = [list(map(int, input().split())) for i in range(n)]
q = [int(input()) for i in range(Q)]
stx.sort(key=lambda x: x[2])
ans = [-1 for i in range(Q)]
skip = [-1 for i in range(Q)]
for (s, t, x) in stx:
	begin = bisect_left(q, s - x)
	end = bisect_left(q, t - x)
	while begin < end:
		if skip[begin] == -1:
			ans[begin] = x
			skip[begin] = end
			begin += 1
		else:
			begin = skip[begin]
for e in ans:
	print(e)


def main():
	from bisect import bisect_left
	from collections import namedtuple
	from operator import attrgetter
	import sys
	input = sys.stdin.readline
	Event = namedtuple('Event', 'pos start end')
	(N, Q) = map(int, input().split())
	events = []
	for _ in range(N):
		(s, t, x) = map(int, input().split())
		e = Event(pos=x, start=s - x, end=t - x)
		events.append(e)
	events.sort(key=attrgetter('pos'))
	D = [int(input()) for _ in range(Q)]
	ans = [-1] * Q
	see = [-1] * Q
	for e in events:
		left = bisect_left(D, e.start)
		right = bisect_left(D, e.end)
		idx = left
		while idx < right:
			if ~ans[idx]:
				idx = see[idx]
				continue
			ans[idx] = e.pos
			see[idx] = right
			idx += 1
	print(*ans, sep='\n')

def __starting_point():
	main()
__starting_point()


from bisect import bisect_left
from sys import stdin
readl = stdin.readline
(N, Q) = map(int, readl().rstrip().split())
STX = [list(map(int, readl().rstrip().split())) for _ in range(N)]
Dn = [None for _ in range(Q + 1)]
for i in range(Q):
	Dn[i] = int(readl().rstrip())
Dn[Q] = 10 ** 10
ans = [-1] * (Q + 1)
skip = [-1] * (Q + 1)
for (s, t, x) in sorted(STX, key=lambda x: x[2]):
	l = bisect_left(Dn, s - x)
	r = bisect_left(Dn, t - x)
	while l < r:
		if skip[l] < 0:
			ans[l] = x
			skip[l] = r
			l += 1
		else:
			l = skip[l]
for d in ans[:-1]:
	print(d)


import bisect
(n, q) = list(map(int, input().split()))
rws = [list(map(int, input().split())) for _ in range(n)]
ds = [int(input()) for _ in range(q)]
rws.sort(key=lambda x: x[2])
ans = [-1 for _ in range(q)]
nxt = [-1 for _ in range(q)]
for rw in rws:
	st = bisect.bisect_left(ds, rw[0] - rw[2])
	en = bisect.bisect_left(ds, rw[1] - rw[2])
	while st < en:
		if nxt[st] == -1:
			ans[st] = rw[2]
			nxt[st] = en
			st += 1
		else:
			st = nxt[st]
for a in ans:
	print(a)


(N, Q) = map(int, input().split())
STX = [tuple(map(int, input().split())) for i in range(N)]
D = [int(input()) for i in range(Q)]
starts = []
ends = []
for (i, (s, t, x)) in enumerate(STX):
	starts.append((s - x, i))
	ends.append((t - x, i))
starts.sort(key=lambda x: x[0], reverse=True)
ends.sort(key=lambda x: x[0], reverse=True)
import heapq
hq = []
heapq.heapify(hq)
delset = set()
ans = []
for d in D:
	while starts and starts[-1][0] <= d:
		(_, i) = starts.pop()
		x = STX[i][2]
		heapq.heappush(hq, x * N + i)
	while ends and ends[-1][0] <= d:
		(_, i) = ends.pop()
		delset.add(i)
	while hq:
		i = hq[0] % N
		if i in delset:
			heapq.heappop(hq)
		else:
			break
	if len(hq) == 0:
		ans.append(-1)
	else:
		ans.append(hq[0] // N)
print(*ans, sep='\n')