CodeEff/ECCO huggingface dataset:
# Original solution
from bisect import bisect_left

N,Q = map(int, input().split())
STX = []
for i in range(N):
  *stx, = list(map(int, input().split()))
  STX.append(stx)
D = []
for i in range(Q):
  D.append(int(input()))

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

DI = [i for i in range(Q)]
ANS = [-1]*Q
for (s,t,x) in STX:
  s2 = (s - x)
  t2 = (t - x)

  D_sub = [D[di] for di in DI]
  start = bisect_left(D_sub, s2)
  end = bisect_left(D_sub, t2, lo=start)
    
  #print(start, end, DI)
  DI_copy = DI[:]
  while (start < end):
    di = DI_copy[start]
    ANS[di] = x
    DI.remove(di)
    start += 1

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


# Optimized solution
from bisect import bisect_left

N,Q = map(int, input().split())
STX = []
for i in range(N):
  *stx, = list(map(int, input().split()))
  STX.append(stx)
D = []
for i in range(Q):
  D.append(int(input()))

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)

  #print(start, end, DI)
  while (start < end):
    if (-1 == mask[start]):
      ANS[start] = x
      mask[start] = end
      start += 1
    else:
      start = mask[start]


print(*ANS, sep='\n')
# Original solution
import sys
input = sys.stdin.readline

n, q = list(map(int, input().split()))
events = []
for _ in range(n):
    s, t, x = list(map(int, input().split()))
    events.append((s-x-0.5, 's', x)) # start construction
    events.append((t-x-0.5, 'e', x)) # end construction

for i in range(q):
    d = int(eval(input()))
    events.append((d, 'q', i)) # query
    
events = sorted(events)
is_stop = False
stops = set()
min_stop = float('inf')
ans = [-1]*q
for t, e, x in events: # time, event, distance/index
    if e == 's':
        stops.add(x)
        if x < min_stop:
            min_stop = x
            is_stop = True
    elif e == 'e':
        stops.remove(x)
        if min_stop == x:
            is_stop = False
    elif len(stops) > 0:
        if not is_stop:
             min_stop = min(stops)
             is_stop = True
        ans[x] = min_stop
         
print(('\n'.join(map(str,ans))))

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

n, q = list(map(int, input().split()))
events = []
for _ in range(n):
    s, t, x = list(map(int, input().split()))
    events.append((s-x-0.5, 1, x)) # start construction
    events.append((t-x-0.5, -1, x)) # end construction

for i in range(q):
    d = int(eval(input()))
    events.append((d, 0, i)) # query
    
events = sorted(events)
is_stop = False
stops = set()
min_stop = float('inf')
ans = [-1]*q
for t, e, x in events: # time, event, distance/index
    if e > 0:
        stops.add(x)
        if x < min_stop:
            min_stop = x
            is_stop = True
    elif e < 0:
        stops.remove(x)
        if min_stop == x:
            is_stop = False
    elif len(stops) > 0:
        if not is_stop:
             min_stop = min(stops)
             is_stop = True
        ans[x] = min_stop
         
print(('\n'.join(map(str, ans))))
# Original solution
from bisect import bisect_left
from operator import itemgetter

N, Q = list(map(int, input().split(" ")))
check_points = [tuple(map(int, input().split(" "))) for _ in range(N)]
querys = [int(eval(input())) for _ in range(Q)]
time = [-1 for _ in range(Q)]
jump = [-1 for _ in range(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)


# Optimized solution
from bisect import bisect_left
from operator import itemgetter

N, Q = list(map(int, input().split(" ")))
check_points = [tuple(map(int, input().split(" "))) for _ in range(N)]
querys = [int(eval(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)
# Original solution
from bisect import bisect_left
from operator import itemgetter

N, Q = list(map(int, input().split(" ")))
check_points = [tuple(map(int, input().split(" "))) for _ in range(N)]
querys = [int(eval(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)


# Optimized solution
from bisect import bisect_left
from operator import itemgetter
import sys

input = sys.stdin.readline

N, Q = list(map(int, input().split(" ")))
check_points = [tuple(map(int, input().split(" "))) for _ in range(N)]
querys = [int(eval(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)
# Original solution
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, q = list(map(int, readline().split()))
    event = [0] * (2 * n + q)

    for i in range(n):
        s, t, x = list(map(int, readline().split()))
        event[i * 2] = (s - x, x, 0)
        event[i * 2 + 1] = (t - x, x, 1)

    for i in range(q):
        d = int(eval(input()))
        event[2 * n + i] = (d, 0, 2)

    from operator import itemgetter
    event.sort(key=itemgetter(0))
    stop = set()
    
    for t, x, ev_type in event:
        if ev_type == 0:
            stop.add(x)
        elif ev_type == 1:
            stop.discard(x)
        else:
            if stop:
                print((min(stop)))
            else:
                print((-1))


if __name__ == '__main__':
    main()


# Optimized solution
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, q = list(map(int, readline().split()))
    event = [0] * (2 * n + q)

    for i in range(n):
        s, t, x = list(map(int, readline().split()))
        event[i * 2] = (s - x, x, 0)
        event[i * 2 + 1] = (t - x, x, 1)

    for i in range(q):
        d = int(eval(input()))
        event[2 * n + i] = (d, 0, 2)

    from operator import itemgetter
    event.sort(key=itemgetter(0))
    stop = set()
    res = INF

    for t, x, ev_type in event:
        if ev_type == 0:
            stop.add(x)
            if res == -1:
                res = x
            elif res > x:
                res = x
        elif ev_type == 1:
            stop.discard(x)
            if res == x:
                if stop:
                    res = min(stop)
                else:
                    res = -1
        else:
            if stop:
                print(res)
            else:
                print((-1))


if __name__ == '__main__':
    main()
# Original solution
import sys
input = sys.stdin.readline

from heapq import heappop, heappush
from collections import defaultdict

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

lst = []
l_append = lst.append
for i in range(N):
    s, t, x = list(map(int, input().split()))
    l_append((t - x, 0, x)) #xで止まらなくなる
    l_append((s - x, 1, x)) #xで止まる

for i in range(Q):
    l_append((int(eval(input())), 2, i))

lst.sort()
ans = [-1] * Q

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

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

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

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

from heapq import heappop, heappush
from collections import defaultdict

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

lst = []
l_append = lst.append
for i in range(N):
    s, t, x = list(map(int, input().split()))
    l_append((t - x, 0, x)) #xで止まらなくなる
    l_append((s - x, 1, x)) #xで止まる

for i in range(Q):
    l_append((int(eval(input())), 2, i))

lst.sort()
ans = [-1] * Q

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

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

print(('\n'.join(map(str, ans))))
# Original solution
def main():
    import sys
    from collections import defaultdict
    from heapq import heappop, heappush
    input = sys.stdin.readline

    N, Q = list(map(int, input().split()))
    used = defaultdict(int)
    tank = []
    
    p = []
    p_append = p.append
    for i in range(N):
        s, t, x = list(map(int, input().split()))
        p_append((s - x, x))
        p_append((t - x, -x))
    p.sort()

    cnt = 0
    for i in range(Q):
        d = int(eval(input()))
        while cnt <= len(p) - 1 and p[cnt][0] <= d:
            w = p[cnt][1]
            if w >= 0:
                used[w] += 1
                heappush(tank, w)
            else:
                used[-w] -= 1
            cnt += 1
        while True:
            if len(tank) == 0:
                print((-1))
                break
            kouho = tank[0]
            if used[kouho] > 0:
                print (kouho)
                break
            else:
                heappop(tank)

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    import sys
    input = sys.stdin.readline
    from bisect import bisect_left

    N, Q = list(map(int, input().split()))
    c = []
    c_append = c.append
    for _ in range(N):
        s, t, x = list(map(int, input().split()))
        c_append((x, s, t))
    c.sort()

    D = [int(eval(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))))

if __name__ == '__main__':
    main()
# Original solution
import bisect
n, q = list(map(int, input().split()))

ran = []
for i in range(n):
    s, t, x = list(map(int, input().split()))
    ran.append((s-x, t-x-1, x))
ran.sort(key=lambda a: a[2])

qu = []
convert = {}
for i in range(q):
    que = int(eval(input()))
    convert[que] = i
    qu.append(que)
qu.sort()

memo = [-1] * q

ans = [-1] * q

for i in range(n):
    x = ran[i][2]
    l = ran[i][0]
    r = ran[i][1]
    ql = bisect.bisect_left(qu, l)
    qr = bisect.bisect_right(qu, r)
    if ql >= qr:
        continue
    while ql < qr:
        if memo[ql] >= 0:
            ql = memo[ql]
        else:
            memo[ql] = qr
            ans[convert[qu[ql]]] = x
            ql += 1

for i in ans:
    print(i)

# Optimized solution
import sys
input = sys.stdin.readline
import bisect
n, q = list(map(int, input().split()))

ran = []
for i in range(n):
    s, t, x = list(map(int, input().split()))
    ran.append((s-x, t-x-1, x))
ran.sort(key=lambda a: a[2])

qu = []
convert = {}
for i in range(q):
    que = int(eval(input()))
    convert[que] = i
    qu.append(que)
qu.sort()

memo = [-1] * q

ans = [-1] * q

for i in range(n):
    x = ran[i][2]
    l = ran[i][0]
    r = ran[i][1]
    ql = bisect.bisect_left(qu, l)
    qr = bisect.bisect_right(qu, r)
    if ql >= qr:
        continue
    while ql < qr:
        if memo[ql] >= 0:
            ql = memo[ql]
        else:
            memo[ql] = qr
            ans[convert[qu[ql]]] = x
            ql += 1

for i in ans:
    print(i)
# Original solution
def main():
    import sys,heapq
    from collections import defaultdict
    input = sys.stdin.readline

    n,q = list(map(int,input().split()))
    #used[i]:0より大きいならi
    used = defaultdict(int)
    tank = []

    p = []
    for i in range(n):
        s,t,x = list(map(int,input().split()))
        p.append((s-x,x))
        p.append((t-x-0.5,x))
    p.sort()

    cnt = 0
    for i in range(q):
        d = int(eval(input()))
        while cnt<=len(p)-1 and p[cnt][0] <= d:
            w = p[cnt][1]
            if int(p[cnt][0]) == p[cnt][0]:
                used[w] += 1
                heapq.heappush(tank,w)
            else:
                used[w] -= 1
            cnt += 1
        while True:
            if len(tank) == 0:
                print((-1))
                break
            kouho = tank[0]
            if used[kouho] > 0:
                print(kouho)
                break
            else:
                heapq.heappop(tank)
if __name__ == '__main__':
    main()

# Optimized solution
def main():
    import sys,heapq
    from collections import defaultdict
    input = sys.stdin.readline

    n,q = list(map(int,input().split()))
    #used[i]:0より大きいならi
    used = defaultdict(int)
    tank = []

    p = []
    for i in range(n):
        s,t,x = list(map(int,input().split()))
        p.append((s-x,x))
        p.append((t-x,-x))
    p.sort()

    cnt = 0
    for i in range(q):
        d = int(eval(input()))
        while cnt<=len(p)-1 and p[cnt][0] <= d:
            w = p[cnt][1]
            if w>=0:
                used[w] += 1
                heapq.heappush(tank,w)
            else:
                used[-w] -= 1
            cnt += 1
        while True:
            if len(tank) == 0:
                print((-1))
                break
            kouho = tank[0]
            if used[kouho] > 0:
                print(kouho)
                break
            else:
                heapq.heappop(tank)
if __name__ == '__main__':
    main()
# Original solution
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])
# stop_arr.sort(key=lambda x:x[2], reverse=True)
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")


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

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 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 = update_skip(skip_arr, l)

print(*ans_arr, sep="\n")
# Original solution
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)

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 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 = update_skip(skip_arr, l)

print(*ans_arr, sep="\n")


# Optimized solution
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")
# Original solution
import sys
input = sys.stdin.readline
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], reverse=True)

ans_arr = [-1]*Q

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)
    for i in range(q_start, q_stop):
        ans_arr[i] = x

print(*ans_arr, sep="\n")


# Optimized solution
import sys
input = sys.stdin.readline
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")
# Original solution
import sys
import bisect
 
N, Q = list(map(int, input().split(' ')))
G = [list(map(int, sys.stdin.readline().split(' '))) for _ in range(N)]
T = [int(sys.stdin.readline()) for _ in range(Q)]
 
G.sort(key = lambda x : -x[2])

class SegTree :
    def __init__(self, n) :
        self.n = n
        self.A = [None] * (2 << (n + 1).bit_length())
 
    def update(self, i, l, r, ll, rr, val) :
        if r <= ll or rr <= l :
            return
        if ll <= l and r <= rr :
            self.A[i] = val
            return
 
        if self.A[i] != None :
            self.A[i * 2] = self.A[i * 2 + 1] = self.A[i]
            self.A[i] = None
 
        m = (l + r) // 2
        self.update(i * 2, l, m, ll, rr, val)
        self.update(i * 2 + 1, m, r, ll, rr, val)
 
    def get(self, i, l, r, p) :
        while True :
            if self.A[i] != None or l + 1 == r :
                return self.A[i]
            m = (l+r) // 2
            if p < m :
                i = i * 2
                r = m
            else :
                i = i * 2 + 1
                l = m
 
ST = SegTree(Q)
for g in G :
    s = max(0, g[0] - g[2])
    e = g[1] - g[2]
    if e <= 0 :
        continue
 
    ll = bisect.bisect_left(T, s)
    rr = bisect.bisect_left(T, e)
 
    if ll == rr :
        continue
 
    ST.update(1, 0, Q, ll, rr, g[2])
 
for i in range(Q) :
    ans = ST.get(1, 0, Q, i)
    if ans == None :
        print((-1))
    else :
        print(ans)


# Optimized solution
import sys
import bisect
 
N, Q = list(map(int, input().split(' ')))
G = [list(map(int, sys.stdin.readline().split(' '))) for _ in range(N)]
T = [int(sys.stdin.readline()) for _ in range(Q)]

class SegTree :
    def __init__(self, n) :
        self.n = n
        self.A = [10**15] * (2 << (n + 1).bit_length())
 
    def update(self, l, r, val) :
      l += len(self.A) // 2
      r += len(self.A) // 2
      while l < r:
          if l & 1 :
              self.A[l] = min(self.A[l], val)
              l += 1
          if r & 1:
              self.A[r-1] = min(self.A[r-1], val)
              r -= 1
          l //= 2
          r //= 2

    def get(self, i) :
      i += len(self.A) // 2
      ret = self.A[i]
      while i > 0 :
          i //= 2
          ret = min(ret, self.A[i])
      return ret if ret < 10**15 else -1

ST = SegTree(Q)
for g in G :
    s = g[0] - g[2]
    e = g[1] - g[2]
 
    ll = bisect.bisect_left(T, s)
    rr = bisect.bisect_left(T, e)
 
    if ll == rr :
        continue
 
    ST.update(ll, rr, g[2])
 
for i in range(Q) :
    ans = ST.get(i)
    print(ans)
# Original solution
N,Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(eval(input())) for _ in range(Q)]

L = [(s-x-0.5, t-x-0.5,x) for s,t,x in STX] + [(d,) for d in D]
L.sort()

import heapq
hp = [] # (x,t-x)を入れる

for l in L:
  if len(l)==1:
    while hp and l[0] > hp[0][1]:
      heapq.heappop(hp)
    if hp:
      print((hp[0][0]))
    else:
      print((-1))
  else:
    heapq.heappush(hp, (l[2],l[1]))

# Optimized solution
N,Q = list(map(int, input().split()))
STX = [list(map(int, input().split())) for _ in range(N)]
D = [int(eval(input())) for _ in range(Q)]

L = [(s-x-0.5, t-x-0.5,x) for s,t,x in STX] + [(d,) for d in D]
L.sort()

import heapq
hp = [] # xを入れる
memo = {} # x:t-x

for l in L:
  if len(l)==1:
    while hp and l[0] > memo[hp[0]]:
      heapq.heappop(hp)
    if hp:
      print((hp[0]))
    else:
      print((-1))
  else:
    heapq.heappush(hp, l[2])
    memo[l[2]]=l[1]
# Original solution
import heapq
def main():
    N, Q = list(map(int, input().split()))
    ls = []
    lt = []
    for _ in range(N):
        s, t, x = list(map(int, input().split()))
        ls.append((s-x, x))
        lt.append((t-x, x))
    ls.sort(reverse=True)
    lt.sort(reverse=True)
    dh = []
    dl = []
    for i in range(Q):
        d = int(eval(input()))
        while ls and ls[-1][0] <= d:
            s, x = ls.pop()
            heapq.heappush(dl, x)
        while lt and lt[-1][0] <= d:
                t, x = lt.pop()
                heapq.heappush(dh, x)
        while dl and dh and dl[0] == dh[0]:
            heapq.heappop(dl)
            heapq.heappop(dh)
        if not dl:
            print('-1')
        else:
            print((dl[0]))
main()


# Optimized solution
import heapq
def main():
    N, Q = list(map(int, input().split()))
    l = []
    for _ in range(N):
        s, t, x = list(map(int, input().split()))
        l.append((s-x, 1, x))
        l.append((t-x, 0, x))
    for i in range(Q):
        d = int(eval(input()))
        l.append((d, 2, i))
    r = [-1] * Q
    l.sort()
    h = []
    se = set()
    for a, b, c in l:
        if b == 0:
            se.remove(c)
        elif b == 1:
            se.add(c)
            heapq.heappush(h, c)
        else:
            while h and h[0] not in se:
                heapq.heappop(h)
            r[c] = h[0] if h else -1
    print(('\n'.join(map(str, r))))
            
main()