CodeEff/ECCO huggingface dataset:
# Original solution
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

def main():
	N, Q = list(map(int, input().split()))
	S, T, X = [0] * N, [0] * N, [0] * N
	
	for i in range(N):
		S[i], T[i], X[i] = list(map(int, input().split()))
		
	D = [int(eval(input())) for _ in range(Q)]
	
	event = [] #工事と人を１つのリストで管理: (時間, 出来事の種類, [工事の位置])
	#出来事の種類: (0: 工事の終了、1: 工事の開始、2: 人)
	working = [] #現在行われている工事のリスト
	n = 0 #現在行われている工事の数
	
	for i in range(Q):
		event.append((D[i], 2))
		
	for i in range(N):
		bisect.insort(event, (S[i] - X[i] - 0.5, 1, X[i]))
		bisect.insort(event, (T[i] - X[i] - 0.5, 0, X[i]))
		
	for l in event:
		if l[1] == 1:
			bisect.insort(working, l[2])
			n += 1
		elif l[1] == 0:
			del working[bisect.bisect(working, l[2]) - 1]
			n -= 1
		else:
			if n > 0:
				print((working[0]))
			else:
				print((-1))
				
main()

# Optimized solution
import bisect
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, Q = list(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] = list(map(int, input().split()))
	work.append((X[i], S[i] - X[i], T[i] - X[i]))

D = [int(eval(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)
# Original solution
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,i))
    while ends and ends[-1][0] <= d:
        _,i = ends.pop()
        delset.add(i)
    while hq:
        _,i = hq[0]
        if i in delset:
            heapq.heappop(hq)
        else:
            break
    if len(hq)==0:
        ans.append(-1)
    else:
        x,i = hq[0]
        ans.append(x)

print(*ans, sep='\n')


# Optimized solution
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')
# Original solution
import sys
input = sys.stdin.readline
from bisect import bisect_left

# 区間更新 1点取得
class SegmentTree:
    def __init__(self, N):
        tmp = 1
        while tmp < N:
            tmp <<= 1
        # self.N : 完全二分木の葉の数(N以上の最小の2べき)
        self.N = tmp
        # 2*self.N - 1 : 完全二分木のノード数
        # 1-indexedで管理するので1プラス
        self.data = [float('inf') for _ in range(2*self.N)]

    # [l, r)
    # 入力は0-indexedなので注意
    def update(self, l, r, x):
        L = l + self.N
        R = r + self.N
        while L < R:
            if L & 1:
                self.data[L] = min([self.data[L], x])
                L += 1
            if R & 1:
                R -= 1
                self.data[R] = min([self.data[R], x])
            L >>= 1
            R >>= 1

    def query(self, k):
        k += self.N
        res = self.data[k]
        while k != 1:
            k >>= 1
            res = min(res, self.data[k])
        return res



def main():
    N, Q = list(map(int, input().split()))
    road = []
    for _ in range(N):
        S, T, X = list(map(int, input().split()))
        road.append((S,T,X))

    D = [int(eval(input())) for _ in range(Q)]

    st = SegmentTree(Q)
    for S, T, X in road:
        l = bisect_left(D, S - X)
        r = bisect_left(D, T - X)
        st.update(l, r, X)

    for q in range(Q):
        ans = st.query(q)
        if ans == float('inf'):
            print((-1))
        else:
            print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
from bisect import bisect_left
import sys
input = sys.stdin.readline

class SegmentTree():
    def __init__(self,size,func,default):
        self.leaf=2**(size-1).bit_length()
        self.data=[default]*(2*self.leaf-1)
        self.f=func; self.d=default
    def rangeupdate(self,l,r,x):
        l+=self.leaf-1; r+=self.leaf-1
        while l<r:
            if not l&1:
                self.data[l]=self.f(self.data[l],x)
                l+=1
            if not r&1:
                r-=1
                self.data[r]=self.f(self.data[r],x)
            l>>=1; r>>=1
    def getvalue(self,i):
        k=i+self.leaf-1
        ret=self.d
        while k>=0:
            ret=self.f(ret,self.data[k])
            k=(k-1)>>1
        return ret

#最大値            
def segfunc(x,y):
    return max(x,y)

#最小値
def segfunc2(x,y):
    return min(x,y)
#和
def segfunc3(x,y):
    return x | y


def main():
    N, Q = list(map(int, input().split()))
    construction = []
    for _ in range(N):
        S, T, X = list(map(int, input().split()))
        construction.append([S,T,X])

    D = [int(eval(input())) for _ in range(Q)]
    seg = SegmentTree(Q,segfunc2,float('inf'))

    for i in range(N):
        S, T, X = construction[i]
        l = bisect_left(D, S - X)
        r = bisect_left(D, T - X)
        seg.rangeupdate(l, r, X)
    
    for q in range(Q):
        ans = seg.getvalue(q)
        if ans == float('inf'):
            print((-1))
        else:
            print(ans)

if __name__ == "__main__":
    main()
# Original solution
import sys
input=sys.stdin.readline
from bisect import bisect_left
class SegmentTree():
    def __init__(self,size,func,default):
        self.leaf=2**(size-1).bit_length()
        self.data=[default]*(2*self.leaf-1)
        self.f=func; self.d=default
    def rangeupdate(self,l,r,x):
        l+=self.leaf-1; r+=self.leaf-1
        while l<r:
            if not l&1:
                self.data[l]=self.f(self.data[l],x)
                l+=1
            if not r&1:
                r-=1
                self.data[r]=self.f(self.data[r],x)
            l>>=1; r>>=1
    def getvalue(self,i):
        k=i+self.leaf-1
        ret=self.d
        while k>=0:
            ret=self.f(ret,self.data[k])
            k=(k-1)>>1
        return ret

n,q=list(map(int,input().split()))
seg=SegmentTree(q,min,float('inf'))
STX=[list(map(int,input().split())) for _ in range(n)]
D=[int(eval(input())) for _ in range(q)]
for s,t,x in STX:
    seg.rangeupdate(bisect_left(D,s-x),bisect_left(D,t-x),x)
for i in range(q):
    print((-1 if seg.getvalue(i)==float('inf') else seg.getvalue(i)))

# Optimized solution
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')
# Original solution
import sys
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
STX = []
D = []
D2 = []
ans = [0]*Q
timer = 0
m = 0

for _ in range(N):
    stx = list(map(int, input().split()))
    STX.append(stx)
    if stx[2] > m:
        m = stx[2]

for _ in range(Q):
    ds = int(eval(input()))
    D.append(-ds)
    D2.append(-ds)

while True:
    for d in D:
        if d > 0:
            for s in STX:
                if d == s[2] and timer >= s[0] and timer < s[1]:
                    ans[D2.index(d-timer)] = D.pop(D.index(d))
                    break
                
    if D == []:
        break

    elif min(D) >= m:
        for a in ans:
            if a == 0:
                print((-1))
            else:
                print(a)
        break

    D = list([x+1 for x in D])
    timer += 1

# Optimized solution
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')
# Original solution
import bisect


class DualSegmentTree():

    def __init__(self, n):
        INF = float("inf")
        self.size = 1
        while self.size < n:
            self.size *= 2
        self.node = [INF] * (2*self.size - 1)

    def update(self, begin, end, val):
        begin += (self.size - 1)
        end += (self.size - 1)
        while begin < end:
            if (end - 1) & 1:
                end -= 1
                self.node[end] = min(val, self.node[end])
            if (begin - 1) & 1:
                self.node[begin] = min(val, self.node[begin])
                begin += 1
            begin = (begin - 1) // 2
            end = (end - 1) // 2

    def get_val(self, i):
        i += (self.size - 1)
        val = self.node[i]
        while i > 0:
            i = (i - 1) // 2
            val = min(val, self.node[i])
        return val

n, q = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(n)]
d = [int(eval(input())) for i in range(q)]
INF = float("inf")

st = DualSegmentTree(len(d)+1)

for i in range(n):
    a, b = info[i][0] - info[i][2], info[i][1] - info[i][2]  
    l = bisect.bisect_left(d, a)
    r = bisect.bisect_left(d, b)
    st.update(l, r, info[i][2])

for i in range(q):
    tmp = st.get_val(i)
    if tmp == float("inf"):
        print((-1))
    else:
        print(tmp)

# Optimized solution
import sys
import bisect


class DualSegmentTree():

    def __init__(self, n):
        INF = float("inf")
        self.size = 1
        while self.size < n:
            self.size *= 2
        self.node = [INF] * (2*self.size - 1)

    def update(self, begin, end, val):
        begin += (self.size - 1)
        end += (self.size - 1)
        while begin < end:
            if (end - 1) & 1:
                end -= 1
                self.node[end] = min(val, self.node[end])
            if (begin - 1) & 1:
                self.node[begin] = min(val, self.node[begin])
                begin += 1
            begin = (begin - 1) // 2
            end = (end - 1) // 2

    def get_val(self, i):
        i += (self.size - 1)
        val = self.node[i]
        while i > 0:
            i = (i - 1) // 2
            val = min(val, self.node[i])
        return val

n, q = list(map(int, input().split()))
info = [list(map(int, sys.stdin.readline().split())) for i in range(n)]
d = [int(sys.stdin.readline()) for i in range(q)]
INF = float("inf")

st = DualSegmentTree(len(d)+1)

for i in range(n):
    a, b = info[i][0] - info[i][2], info[i][1] - info[i][2]  
    l = bisect.bisect_left(d, a)
    r = bisect.bisect_left(d, b)
    st.update(l, r, info[i][2])

for i in range(q):
    tmp = st.get_val(i)
    if tmp == float("inf"):
        print((-1))
    else:
        print(tmp)
# Original solution
from bisect import bisect,bisect_left
import sys
import itertools
input=sys.stdin.readline

def main():
    n,q=list(map(int,input().split()))
    xst=[]
    for i in range(n):
        s,t,x=list(map(int,input().split()))
        xst.append([x,s,t])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=[int(eval(input())),i]
    ans=[-1]*q
    for u in xst:
        x,s,t=u
        left=s-x
        right=t-x-1
        a=bisect(d,[left])
        b=bisect(d,[right,q+1])
        for u in d[a:b]:
            ans[u[1]]=x
        d=list(itertools.chain(d[:a],d[b:]))
    for u in ans:
        print(u)

if __name__=="__main__":
    main()

# Optimized solution
from bisect import bisect,bisect_left
import sys
input=sys.stdin.readline

def main():
    n,q=list(map(int,input().split()))
    xst=[]
    for i in range(n):
        s,t,x=list(map(int,input().split()))
        xst.append([x,s-x,t-x])
    xst.sort()
    d=[None]*q
    for i in range(q):
        d[i]=int(eval(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)

if __name__=="__main__":
    main()
# Original solution
from math import ceil, log2
import sys


class SegmentTree:
    def __init__(self, length, init_value=None, aggfunc=min):
        self.aggfunc = aggfunc
        self.depth = ceil(log2(length))
        self.data = [init_value] * (2 ** (1 + self.depth) - 1)
        self.origin = 2 ** self.depth - 1

    def update(self, idx, value):
        i = idx + self.origin
        self.data[i] = value
        while i > 0:
            i = (i - 1) // 2
            new_value = self.aggfunc(self.data[i * 2 + 1], self.data[i * 2 + 2])
            if self.data[i] != new_value:
                self.data[i] = new_value
            else:
                break


input = sys.stdin.readline
n, q = list(map(int, input().split()))
stx = [tuple(map(int, input().split())) for _ in range(n)]
d = [int(eval(input())) for _ in range(q)]

xs = set()
events = []

for s, t, x in stx:
    events.append((s - x, 1, x))
    events.append((t - x, -1, x))
    xs.add(x)
events.sort()

xs = list(xs)
xs.sort()


zaatsu = dict(list(zip(xs, list(range(len(xs))))))

ub = 10 ** 9 + 1
koujichu = SegmentTree(len(zaatsu), ub, min)

i = 0
for di in d:
    while i < len(events) and events[i][0] <= di:
        if events[i][1] == 1:
            koujichu.update(zaatsu[events[i][2]], events[i][2])
        else:
            koujichu.update(zaatsu[events[i][2]], ub)
        i += 1
    if koujichu.data[0] != ub:
        print((koujichu.data[0]))
    else:
        print((-1))


# Optimized solution
import sys
from bisect import bisect_left

input = sys.stdin.readline
n, q = list(map(int, input().split()))
stx = [tuple(map(int, input().split())) for _ in range(n)]
d = [int(eval(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)
# Original solution
import sys
from heapq import heappush, heappop
from collections import defaultdict
input = sys.stdin.readline

num, person = list(map(int, input().split()))
arr = []

for i in range(num):
    s, t, x = list(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(eval(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)

# Optimized solution
import sys
from heapq import heappush, heappop
input = sys.stdin.readline

num, person = list(map(int, input().split()))
arr = []

for i in range(num):
    s, t, x = list(map(int, input().split()))
    arr.append((s - x - 0.5, 1, x, i))
    arr.append((t - x - 0.5, 0, x, i))

for i in range(person):
    d = int(eval(input()))
    arr.append((d,))

arr.sort()

heap = []
done = set()

for elem in arr:
    if len(elem) == 1:
        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:
        heappush(heap, (x, i))
    else:
        done.add(i)
# Original solution
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 = [list(map(int, input().split())) for _ in range(N)]
# xの昇順に工事の区間をsort
STX = sorted(STX, key=lambda x: x[2])
 
D = [int(eval(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が更新されていない場合
            ans[now] = x
            index[now] = right
            now += 1
        else:
            now = index[now]
            
 
for a in ans:
    print(a)

# Optimized solution
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(eval(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)
    #print(D)
    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]))
# Original solution
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)]


# for i in range(N):
    # S,T,X =list(map(int,input().split(" ")))
    # lt = S -X -0.5
    # rt = T -X -0.5
    # queries.append([lt,rt,X]) #-1 → 挿入クエリ lが時間、-1がクエリの種類、Xが場所


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:
             temp = jump[lind]
             jump[lind] = rind
             lind = temp

for i  in ans:
    print(i)


# Optimized solution
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)]


# for i in range(N):
    # S,T,X =list(map(int,input().split(" ")))
    # lt = S -X -0.5
    # rt = T -X -0.5
    # queries.append([lt,rt,X]) #-1 → 挿入クエリ lが時間、-1がクエリの種類、Xが場所


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)
# Original solution
import heapq
N,Q = list(map(int,input().split(" ")))
querys = []
START = 1
GOAL = 0
GO = 2

for _ in range(N):
    s,t,x = (list(map(int,input().split(" "))))
    s -=(x + 0.5)
    t -= (x + 0.5)
    querys.append( (s,START,x) )
    querys.append( (t,GOAL,x) )

for _ in range(Q):

    querys.append( (int(eval(input())),GO,-1)  )
koji_place = []
koji_um = set([])
heapq.heapify(koji_place)
querys.sort()
for query in querys:
    time,qtype,place = query
    if qtype == START:
        heapq.heappush(koji_place,place)
        koji_um.add(place)
    elif qtype == GOAL:
        koji_um.remove(place)
    else:
        while koji_place and koji_place[0] not in koji_um: #更新と最近の場所のチェックを同時に行う
            heapq.heappop(koji_place) #koji place のpopは最大で place分，つまり合計で10 ** 5回行われるため ここのwhile
            # はOに影響を与えない
        if koji_place:
            print((koji_place[0]))
        else:
            print((-1))





# Optimized solution
import heapq
import sys
input=sys.stdin.readline

N,Q = list(map(int,input().split(" ")))
querys = []
START = 1
GOAL = 0
GO = 2

for _ in range(N):
    s,t,x = (list(map(int,input().split(" "))))
    s -=(x + 0.5)
    t -= (x + 0.5)
    querys.append( (s,START,x) )
    querys.append( (t,GOAL,x) )

for _ in range(Q):

    querys.append( (int(eval(input())),GO,-1)  )
koji_place = []
koji_um = set([])
heapq.heapify(koji_place)
querys.sort()
for query in querys:
    time,qtype,place = query
    if qtype == START:
        heapq.heappush(koji_place,place)
        koji_um.add(place)
    elif qtype == GOAL:
        koji_um.remove(place)
    else:
        while koji_place and koji_place[0] not in koji_um: #更新と最近の場所のチェックを同時に行う
            heapq.heappop(koji_place) #koji place のpopは最大で place分，つまり合計で10 ** 5回行われるため ここのwhile
            # はOに影響を与えない
        if koji_place:
            print((koji_place[0]))
        else:
            print((-1))
# Original solution
import sys
import bisect

input = sys.stdin.readline

N, Q = list(map(int, input().split()))

STX_array = [list(map(int, input().split())) for _ in range(N)]

STX_array = sorted(STX_array, key=lambda x: x[2])

Q_array = [int(eval(input())) for _ in range(Q)]

index_array = [i for i in range(Q)]

ans_array = [-1] * Q
for STX in STX_array:
    s, t, x = STX
    index_left = bisect.bisect_left(Q_array, s - 0.5 - x)
    index_right = bisect.bisect_left(Q_array, t - 0.5 - x)
    if index_left != index_right:
        for i in index_array[index_left:index_right]:
            ans_array[i] = x

        del Q_array[index_left:index_right]
        del index_array[index_left:index_right]
    if len(Q_array) == 0:
        break
for ans in ans_array:
    print(ans)

# Optimized solution
import sys
import bisect

input = sys.stdin.readline

N, Q = list(map(int, input().split()))

STX_array = [list(map(int, input().split())) for _ in range(N)]

STX_array = sorted(STX_array, key=lambda x: x[2])

Q_array = [int(eval(input())) for _ in range(Q)]

index_array = [i for i in range(Q)]

ans_array = [-1] * Q
for STX in STX_array:
    s, t, x = STX
    index_left = bisect.bisect_left(Q_array, s - 0.5 - x)
    index_right = bisect.bisect_left(Q_array, t - 0.5 - x)
    if index_left != index_right:
        now_index = index_left
        while now_index < index_right:
            if index_array[now_index] == now_index:
                ans_array[now_index] = x
                index_array[now_index] = index_right
                now_index += 1
            else:
                old_index = now_index
                now_index = index_array[now_index]
                index_array[old_index] = now_index




for ans in ans_array:
    print(ans)