CodeEff/ECCO huggingface dataset:
# Original solution
#D in [S_i-X_i,T_i-X_i) → Xiで止まる
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
from collections import defaultdict

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

STX = [[int(x) for x in input().split()] for _ in range(N)]
for s,t,x in STX:
  task.append((t-x,0,x)) # xで止まらなくなる
  task.append((s-x,1,x)) # xで止まる

for i in range(Q):
  d = int(eval(input()))
  task.append((d,2,i)) # 止まる位置を答える
answer = [-1]*Q

task.sort()

# 引っかかってる場所の管理
se = set()
se_hp = [] # heapでソートを保つ

# 小さい時刻から順に見ていく
for a,b,c in task:
  if not b: # b == 0
    se.remove(c)
  elif b&1: # b == 1
    se.add(c)
    heappush(se_hp,c)
  else: # b == 2
    while se_hp and se_hp[0] not in se:
      heappop(se_hp)
    answer[c] = se_hp[0] if se_hp else -1

print(('\n'.join(map(str,answer))))


# Optimized solution
#D in [S_i-X_i,T_i-X_i) → Xiで止まる
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
from collections import defaultdict

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

STX = [[int(x) for x in input().split()] for _ in range(N)]
for s,t,x in STX:
  task.append((t-x,0,x)) # xで止まらなくなる
  task.append((s-x,1,x)) # xで止まる

for i in range(Q):
  d = int(eval(input()))
  task.append((d,2,i)) # 止まる位置を答える
answer = [-1]*Q

task.sort()

# 引っかかってる場所の管理
se = set()
se_hp = [] # heapで最小値を先頭に保つ

# 小さい時刻から順に見ていく
for a,b,c in task:
  if not b: # b == 0
    se.remove(c)
  elif b&1: # b == 1
    se.add(c)
    heappush(se_hp,c)
  else: # b == 2
    while se_hp and se_hp[0] not in se:
      heappop(se_hp)
    answer[c] = se_hp[0] if se_hp else -1

print(('\n'.join(map(str,answer))))
# Original solution
#D in [S_i-X_i,T_i-X_i) → Xiで止まる
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
from collections import defaultdict

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

STX = [[int(x) for x in input().split()] for _ in range(N)]
for s,t,x in STX:
  task.append((t-x,0,x)) # xで止まらなくなる
  task.append((s-x,1,x)) # xで止まる

for i in range(Q):
  d = int(eval(input()))
  task.append((d,2,i)) # 止まる位置を答える
answer = [-1]*Q

task.sort()

# 引っかかってる場所の管理
se = set()
se_hp = [] # heapで最小値を先頭に保つ

# 小さい時刻から順に見ていく
for a,b,c in task:
  if not b: # b == 0
    se.remove(c)
  elif b&1: # b == 1
    se.add(c)
    heappush(se_hp,c)
  else: # b == 2
    while se_hp and se_hp[0] not in se:
      heappop(se_hp)
    answer[c] = se_hp[0] if se_hp else -1

print(('\n'.join(map(str,answer))))


# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappush, heappop
from collections import defaultdict

N,Q = list(map(int,readline().split()))
data = list(map(int,read().split()))
S = data[:3*N:3]
T = data[1:3*N:3]
X = data[2:3*N:3]
D = data[3*N:]

event = []
event += [(s-x,1,x) for x,s in zip(X,S)] # xに通行止めを1つ追加
event += [(t-x,2,x) for x,t in zip(X,T)] # xの通行止めを1つ削除
event += [(x,3,i) for i,x in enumerate(D)] # 最小の通行止めを答える

event.sort()

INF = 10**10
q = [INF]
counter = defaultdict(int)
counter[INF] = 1

answer = [None] * Q
for a,b,c in event:
    if b == 1:
        heappush(q,c)
        counter[c] += 1
    elif b == 2:
        counter[c] -= 1
    else:
        while counter[q[0]] == 0:
            heappop(q)
        x = q[0]
        if x == INF:
            x = -1
        answer[c] = x

print(('\n'.join(map(str,answer))))
# Original solution
#13:12
n,q = list(map(int,input().split()))
import heapq
import sys
input = sys.stdin.readline
event = []
for _ in range(n):
  s,t,x = list(map(int,input().split()))
  heapq.heappush(event,[s-x,t-x,x])
t = 0
now = []
for _ in range(q):
  d = int(eval(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))

# Optimized solution
#13:12
n,q = list(map(int,input().split()))
import heapq
import sys
input = sys.stdin.readline
event = []
for _ in range(n):
  s,t,x = list(map(int,input().split()))
  heapq.heappush(event,(s-x,t-x,x))
t = 0
now = []
for _ in range(q):
  d = int(eval(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))
# Original solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 15 16:58:00 2019

@author: YudNK
"""
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

for e in E:
    l = bs.bisect_left(D, e[0])
    r = bs.bisect_left(D, e[1])
    for i in range(l, r):
        if ans[i] == -1:
            ans[i] = e[2]
        else:
            pass
    
[print(i) for i in ans]


# Optimized solution
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 15 16:58:00 2019

@author: YudNK
"""
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]
# Original solution
N, Q = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
X.sort(key = lambda x: x[2])
X.append([-1, 1, X[-1][2] + 1])

def quitConst(t):
  nextx = [x for x in X if x[1] > t + x[2] or x[0] == -1]
  return nextx
def startConst(t):
  nextx = [x for x in X if x[0] <= t + x[2] or x[0] == -1]
  return nextx
for _ in range(Q):
  current = 0
  start = int(eval(input()))
  X = quitConst(start)
  XX = startConst(start)
  for x in XX:
    current = x[2]
    if x[0] <= current + start < x[1]:
      break
  if current == XX[-1][2]:
    print((-1))
  else:
    print(current)

# Optimized solution
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')
# Original solution
if __name__ == '__main__':
    N,Q=list(map(int,input().split()))
    events=[list(map(int,input().split())) for _ in range(N)]
    D=[int(eval(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]=X
                skip[left]=right
                left+=1
            else:
                left=skip[left]
    for i in ans:
        print(i)


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


n, q = list(map(int, input().split()))
events = [list(map(int, input().split())) for _ in range(n)]
events.sort(key=lambda x: x[2])

departures = [int(eval(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)))
# Original solution
if __name__ == '__main__':
    N,Q=list(map(int,input().split()))
    events=[list(map(int,input().split())) for _ in range(N)]
    D=[int(eval(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)))


# Optimized solution
if __name__ == '__main__':
    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(eval(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)))
# Original solution
from bisect import bisect_left, bisect_right
from operator import itemgetter
import sys
input = sys.stdin.readline
INF = float("inf")


def main():
    N, Q = list(map(int, input().split()))
    constructions = [None] * N
    for i in range(N):
        S, T, X = list(map(int, input().split()))
        constructions[i] = (S, T, X)
    D = [int(eval(input())) for _ in range(Q)]
    ans = [INF] * Q
    for S, T, X in constructions:
        l = bisect_left(D, S-X)
        r = bisect_right(D, T-X-1)
        for idx in range(l, r):
            ans[idx] = min(X, ans[idx])
    for a in ans:
        if a == INF:
            print((-1))
        else:
            print(a)


if __name__ == "__main__":
    main()


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


def main():
    N, Q = list(map(int, input().split()))
    constructions = [None] * N
    for i in range(N):
        S, T, X = list(map(int, input().split()))
        constructions[i] = (S, T, X)
    constructions.sort(key=itemgetter(2))
    D = [int(eval(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)


if __name__ == "__main__":
    main()
# Original solution
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(eval(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,1,X])
        origST.append([T-X,-1,X])
    origST.sort()
    stidx = 0
    cur_set = set([])
    for idx in range(Q):
        q = int_raw()
        while stidx < len(origST):
            st = origST[stidx]
            if st[0] > q:
                break
            if st[1]>0:
                cur_set.add(st[2])
            else:
                cur_set.remove(st[2])
            stidx+=1
        if len(cur_set)==0:
            print((-1))
        else:
            print((min(cur_set)))

main()


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

def int_raw():
    return int(eval(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(eval(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()
# Original solution
from heapq import heappush,heappop
n,q=list(map(int,input().split()))
e=[]
for i in range(n):
  s,t,x=list(map(int,input().split()))
  e.append((s-x,1,x))
  e.append((t-x,-1,x))
for i in range(q):
  d=int(eval(input()))
  e.append((d,2,0))
e.sort()
s=set()
a=[]
for time_,type_,x_ in e:
  if type_==1:
    s.add(x_)
    heappush(a,x_)
  elif type_==-1:
    s.remove(x_)
  else:
    while a and a[0] not in s:
      heappop(a)
    if a:
      print((a[0]))
    else:
      print((-1))

# Optimized solution
import sys
from heapq import heappush,heappop
input=sys.stdin.readline
n,q=list(map(int,input().split()))
e=[]
for i in range(n):
  s,t,x=list(map(int,input().split()))
  e.append((s-x,1,x))
  e.append((t-x,-1,x))
for i in range(q):
  d=int(eval(input()))
  e.append((d,2,0))
e.sort()
s=set()
a=[]
for time_,type_,x_ in e:
  if type_==1:
    s.add(x_)
    heappush(a,x_)
  elif type_==-1:
    s.remove(x_)
  else:
    while a and a[0] not in s:
      heappop(a)
    if a:
      print((a[0]))
    else:
      print((-1))
# Original solution
import sys
input = sys.stdin.readline

def main():

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

    V = []

    for i in range(n):
        s, t, x = list(map(int, input().split()))
        V.append((s-x, x, 1)) #1: insert
        V.append((t-x, x, 0)) #0: delete

    D = []
    for i in range(q):
        d = int(eval(input()))
        V.append((d, i, 2)) #2: query

    V.sort(key=lambda x:(x[0], x[2]))
    se = set()
    hq = []
    import heapq
    heapq.heapify(hq)
    ans = [-1]*q
    for t, v, p in V:
        if p == 1:
            se.add(v)
            heapq.heappush(hq, v)
        elif p == 0:
            se.discard(v)
        else:
            while hq and hq[0] not in se:
                heapq.heappop(hq)
            if hq:
                ans[v] = hq[0]

    for i in range(q):
        print((ans[i]))

if __name__ == '__main__':
    main()

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

def main():

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

    V = []

    for i in range(n):
        s, t, x = list(map(int, input().split()))
        V.append((s-x, x, 1)) #1: insert
        V.append((t-x, x, 0)) #0: delete

    D = []
    for i in range(q):
        d = int(eval(input()))
        V.append((d, i, 2)) #2: query

    V.sort(key=lambda x:(x[0], x[2]))
    se = set()
    hq = []
    import heapq
    heapq.heapify(hq)
    ans = [-1]*q
    for t, v, p in V:
        if p == 1:
            se.add(v)
            heapq.heappush(hq, v)
        elif p == 0:
            se.remove(v)
        else:
            while hq and hq[0] not in se:
                heapq.heappop(hq)
            if hq:
                ans[v] = hq[0]

    for i in range(q):
        print((ans[i]))

if __name__ == '__main__':
    main()
# Original solution
import heapq
import sys
sys.setrecursionlimit(10 ** 7)

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

event=[]
for _ in range(n):
    s,t,x=list(map(int,input().split()))
    event.append([s-x,1,x])
    event.append([t-x,-1,x])

for i in range(q):
    event.append([int(eval(input())),2,i])
event.sort()

ans=[0]*q

stop=set()
hq=[]
for e in event:
    t,op,x=[x for x in e]
    if op==1:
        heapq.heappush(hq,x)
        stop.add(x)
    elif op==-1:
        stop.remove(x)

    else:
        while hq and hq[0] not in stop:
            heapq.heappop(hq) 
        ans[x]=hq[0] if hq else -1
    
for x in ans:
    print(x)

# Optimized solution
import heapq
import sys
sys.setrecursionlimit(10 ** 7)

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

event=[]
for _ in range(n):
    s,t,x=list(map(int,input().split()))
    event.append((s-x,1,x))
    event.append((t-x,-1,x))

for i in range(q):
    event.append((int(eval(input())),2,i))
event.sort()

ans=[0]*q

stop=set()
hq=[]
for t,op,x in event:
    if op==1:
        heapq.heappush(hq,x)
        stop.add(x)
    elif op==-1:
        stop.remove(x)

    else:
        while hq and hq[0] not in stop:
            heapq.heappop(hq) 
        ans[x]=hq[0] if hq else -1
    
for x in ans:
    print(x)
# Original solution
from heapq import heappush, heappop
import sys
sys.setrecursionlimit(10 ** 7)

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

event=[]
for _ in range(n):
    s,t,x=list(map(int,input().split()))
    event.append((s-x,1,x))
    event.append((t-x,-1,x))

for i in range(q):
    event.append((int(eval(input())),2,i))
event.sort()

ans=[0]*q

stop=set()
hq=[]
for t,op,x in event:
    if op==1:
        heappush(hq,x)
        stop.add(x)
    elif op==-1:
        stop.remove(x)

    else:
        while hq and hq[0] not in stop:
            heappop(hq) 
        ans[x]=hq[0] if hq else -1
    
for x in ans:
    print(x)

# Optimized solution
def main():
    from heapq import heappush, heappop
    import sys
    sys.setrecursionlimit(10 ** 7)

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

    event=[]
    for _ in range(n):
        s,t,x=list(map(int,input().split()))
        event.append((s-x,1,x))
        event.append((t-x,-1,x))

    for i in range(q):
        event.append((int(eval(input())),2,i))
    event.sort()

    ans=[0]*q

    stop=set()
    hq=[]
    for t,op,x in event:
        if op==1:
            heappush(hq,x)
            stop.add(x)
        elif op==-1:
            stop.remove(x)

        else:
            while hq and hq[0] not in stop:
                heappop(hq) 
            ans[x]=hq[0] if hq else -1
        
    for x in ans:
        print(x)

main()
# Original solution
def main():
    from heapq import heappush, heappop
    import sys
    sys.setrecursionlimit(10 ** 7)

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

    event=[]
    for _ in range(n):
        s,t,x=list(map(int,input().split()))
        event.append((s-x,1,x))
        event.append((t-x,-1,x))

    for i in range(q):
        event.append((int(eval(input())),2,i))
    event.sort()

    ans=[0]*q

    stop=set()
    hq=[]
    for t,op,x in event:
        if op==1:
            heappush(hq,x)
            stop.add(x)
        elif op==-1:
            stop.remove(x)

        else:
            while hq and hq[0] not in stop:
                heappop(hq) 
            ans[x]=hq[0] if hq else -1
        
    for x in ans:
        print(x)

main()

# Optimized solution
from heapq import heappush, heappop
import sys
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, Q = list(map(int, readline().split()))
STX = [[int(x) for x in readline().split()] for _ in range(N)]
EVENT = []
for s, t, x in STX:
    EVENT.append((s-x, 1, x))
    EVENT.append((t-x, 0, x))

for i in range(Q):
    d = int(readline())
    EVENT.append((d, 2, i))

ans = [-1] * Q

EVENT.sort()


STOP = set()
h = []
for t, op, x in EVENT:
    if op == 2 and STOP:
        while h and h[0] not in STOP:
            heappop(h)
        ans[x] = h[0]
    elif op == 1:
        STOP.add(x)
        heappush(h, x)
    elif op == 0:
        STOP.remove(x)

print(("\n".join(map(str, ans))))
# Original solution
def main():
    from heapq import heappush, heappop
    import sys
    sys.setrecursionlimit(10 ** 7)
    
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines

    n,q=list(map(int,readline().split()))
    stx = [[int(x) for x in readline().split()] for _ in range(n)]
    event=[]
    stop=set()
    for s,t,x in stx:
        event.append([s-x,1,x])
        event.append([t-x,-1,x])
    for i in range(q):
        event.append([int(eval(input())),2,i])
    event.sort()
    
    ans=[0]*q
    
    stop=set()
    hq=[]
    for e in event:
        t,op,x=[x for x in e]
        if op==1:
            heappush(hq,x)
            stop.add(x)
        elif op==-1:
            stop.remove(x)
    
        else:
            while hq and hq[0] not in stop:
                heappop(hq) 
            ans[x]=hq[0] if hq else -1
        
    for x in ans:
        print(x)

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    from heapq import heappush, heappop
    import sys
    sys.setrecursionlimit(10 ** 7)
    
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines

    n,q=list(map(int,readline().split()))
    stx = [[int(x) for x in readline().split()] for _ in range(n)]
    event=[]
    stop=set()
    for s,t,x in stx:
        event.append([s-x,1,x])
        event.append([t-x,-1,x])
    for i in range(q):
        event.append([int(eval(input())),2,i])
    event.sort()
    
    ans=[0]*q
    
    stop=set()
    hq=[]
    for t,op,x in event:
        if op==1:
            heappush(hq,x)
            stop.add(x)
        elif op==-1:
            stop.remove(x)
    
        else:
            while hq and hq[0] not in stop:
                heappop(hq) 
            ans[x]=hq[0] if hq else -1
        
    for x in ans:
        print(x)

if __name__ == "__main__":
    main()
# Original solution
import heapq
N,Q=list(map(int,input().split()))

event_list=[]
for i in range(N):
  S,T,X=list(map(int,input().split()))
  event_list.append((S-X-0.5,1,X))
  event_list.append((T-X-0.5,-1,X))
  
dlist=[]
for i in range(Q):
  D=int(eval(input()))
  event_list.append((D,0,X))  
  dlist.append(D)
event_list.sort()
#print(event_list)

answer_dic={}
stop_set=set()
min_set=10**9
for t,f,x in event_list:
  if f==1:
    stop_set.add(x)
    if x<min_set:
      min_set=x
  elif f==-1:
    stop_set.remove(x)
    if x==min_set:
      if len(stop_set)>0:
        min_set=min(stop_set)
      else:
        min_set=10**9
  else:
    if len(stop_set)>0:
      answer_dic[t]=min_set
    else:
      answer_dic[t]=-1
#print(answer_dic)

for d in dlist:
  print((answer_dic[d]))

# Optimized solution
import heapq
import sys
input=sys.stdin.readline
N,Q=list(map(int,input().split()))

event_list=[]
for i in range(N):
  S,T,X=list(map(int,input().split()))
  event_list.append((S-X-0.5,1,X))
  event_list.append((T-X-0.5,-1,X))
  
dlist=[]
for i in range(Q):
  D=int(eval(input()))
  event_list.append((D,0,X))  
  dlist.append(D)
event_list.sort()
#print(event_list)

answer_dic={}
stop_set=set()
min_set=float("inf")
for t,f,x in event_list:
  if f==1:
    stop_set.add(x)
    if x<min_set:
      min_set=x
  elif f==-1:
    stop_set.remove(x)
    if x==min_set:
      if len(stop_set)>0:
        min_set=min(stop_set)
      else:
        min_set=float("inf")
  else:
    if len(stop_set)>0:
      answer_dic[t]=min_set
    else:
      answer_dic[t]=-1
#print(answer_dic)

for d in dlist:
  print((answer_dic[d]))