CodeEff/ECCO huggingface dataset:
# Original solution
import bisect


class SegTree:

    def __init__(self, n):
        # supposed that n = 2**m
        INF = 10 ** 12
        self.n = n
        self.val = [INF for _ in range(2 * n + 1)]

    def _update(self, a, b, v, k, l, r):
        if r <= a or b <= l:
            return
        if a <= l and r <= b:
            self.val[k] = min(v, self.val[k])
        else:
            self._update(a, b, v, 2 * k + 1, l, (l + r) // 2)
            self._update(a, b, v, 2 * k + 2, (l + r) // 2, r)

    def update(self, a, b, v):
        # 区間[a, b)上の値がvより大きければvに更新
        self._update(a, b, v, 0, 0, self.n)

    def query(self, x):
        # ノードxの値を返す
        k = self.n + x - 1
        ret = self.val[k]
        while k > 0:
            k = (k - 1) // 2
            ret = min(ret, self.val[k])
        return ret


def main():
    N, Q = list(map(int, input().split(' ')))
    work_list = [list(map(int, input().split(' '))) for _ in range(N)]
    # 工事は出発地から近い順に並べておく
    work_list.sort(key=lambda work: work[2])
    D = [int(eval(input())) for _ in range(Q)]
    # 一番最初に引っかかる工事のインデックスを求める
    QQ = 1
    while QQ < Q:
        QQ <<= 1
    tree = SegTree(QQ)
    for w in range(N):
        s, t, x = work_list[w]
        # s - x <= d < t - x だと工事に引っかかる
        left = bisect.bisect_left(D, s - x)
        right = bisect.bisect_left(D, t - x)
        tree.update(left, right, w)
    for q in range(Q):
        w = tree.query(q)
        if w >= N:
            print((-1))
        else:
            print((work_list[w][2]))


if __name__ == '__main__':
    main()


# Optimized solution
import bisect


class SegTree:

    def __init__(self, n):
        # supposed that n = 2**m
        INF = 10 ** 12
        self.n = n
        self.val = [INF] * (2 * n - 1)

    def _update(self, a, b, v, k, l, r):
        if r <= a or b <= l:
            return
        if a <= l and r <= b:
            self.val[k] = min(v, self.val[k])
        else:
            self._update(a, b, v, 2 * k + 1, l, (l + r) // 2)
            self._update(a, b, v, 2 * k + 2, (l + r) // 2, r)

    def update(self, a, b, v):
        # 区間[a, b)上の値がvより大きければvに更新
        self._update(a, b, v, 0, 0, self.n)

    def query(self, x):
        # ノードxの値を返す
        k = self.n + x - 1
        ret = self.val[k]
        while k > 0:
            k = (k - 1) // 2
            ret = min(ret, self.val[k])
        return ret


def main():
    N, Q = list(map(int, input().split(' ')))
    work_list = [list(map(int, input().split(' '))) for _ in range(N)]
    # 工事は出発地から近い順に並べておく
    work_list.sort(key=lambda work: work[2])
    D = [int(eval(input())) for _ in range(Q)]
    # 一番最初に引っかかる工事のインデックスを求める
    QQ = 1
    while QQ < Q:
        QQ <<= 1
    tree = SegTree(QQ)
    for w, work in enumerate(work_list):
        s, t, x = work
        # s - x <= d < t - x だと工事に引っかかる
        left = bisect.bisect_left(D, s - x)
        right = bisect.bisect_left(D, t - x)
        tree.update(left, right, w)
    for q in range(Q):
        w = tree.query(q)
        if w >= N:
            print((-1))
        else:
            print((work_list[w][2]))


if __name__ == '__main__':
    main()
# Original solution
import bisect


class SegTree:

    def __init__(self, n):
        # supposed that n = 2**m
        INF = 10 ** 12
        self.n = n
        self.val = [INF] * (2 * n - 1)

    def _update(self, a, b, v, k, l, r):
        if r <= a or b <= l:
            return
        if a <= l and r <= b:
            self.val[k] = min(v, self.val[k])
        else:
            self._update(a, b, v, 2 * k + 1, l, (l + r) // 2)
            self._update(a, b, v, 2 * k + 2, (l + r) // 2, r)

    def update(self, a, b, v):
        # 区間[a, b)上の値がvより大きければvに更新
        self._update(a, b, v, 0, 0, self.n)

    def query(self, x):
        # ノードxの値を返す
        k = self.n + x - 1
        ret = self.val[k]
        while k > 0:
            k = (k - 1) // 2
            ret = min(ret, self.val[k])
        return ret


def main():
    N, Q = list(map(int, input().split(' ')))
    work_list = [list(map(int, input().split(' '))) for _ in range(N)]
    # 工事は出発地から近い順に並べておく
    work_list.sort(key=lambda work: work[2])
    D = [int(eval(input())) for _ in range(Q)]
    # 一番最初に引っかかる工事のインデックスを求める
    QQ = 1
    while QQ < Q:
        QQ <<= 1
    tree = SegTree(QQ)
    for w, work in enumerate(work_list):
        s, t, x = work
        # s - x <= d < t - x だと工事に引っかかる
        left = bisect.bisect_left(D, s - x)
        right = bisect.bisect_left(D, t - x)
        tree.update(left, right, w)
    for q in range(Q):
        w = tree.query(q)
        if w >= N:
            print((-1))
        else:
            print((work_list[w][2]))


if __name__ == '__main__':
    main()

# Optimized solution
import bisect


class SegTree:

    def __init__(self, n):
        # supposed that n = 2**m
        self.n = n
        self.val = [-1] * (2 * n - 1)

    def _update(self, a, b, v, k, l, r):
        if r <= a or b <= l:
            return
        if a <= l and r <= b:
            self.val[k] = v
        else:
            self._update(a, b, v, 2 * k + 1, l, (l + r) // 2)
            self._update(a, b, v, 2 * k + 2, (l + r) // 2, r)

    def update(self, a, b, v):
        # 区間[a, b)上の値をvに更新
        self._update(a, b, v, 0, 0, self.n)

    def query(self, x):
        # ノードxの値を返す
        k = self.n + x - 1
        ret = self.val[k]
        while k > 0:
            k = (k - 1) // 2
            ret = max(ret, self.val[k])
        return ret


def main():
    N, Q = list(map(int, input().split(' ')))
    work_list = [list(map(int, input().split(' '))) for _ in range(N)]
    # 工事は出発地から遠い順に並べておく
    work_list.sort(key=lambda work: work[2], reverse=True)
    D = [int(eval(input())) for _ in range(Q)]
    # 一番最初に引っかかる工事のインデックスを求める
    QQ = 1
    while QQ < Q:
        QQ <<= 1
    tree = SegTree(QQ)
    for w, work in enumerate(work_list):
        s, t, x = work
        # s - x <= d < t - x だと工事に引っかかる
        left = bisect.bisect_left(D, s - x)
        right = bisect.bisect_left(D, t - x)
        tree.update(left, right, w)
    for q in range(Q):
        w = tree.query(q)
        if w == -1:
            print((-1))
        else:
            print((work_list[w][2]))


if __name__ == '__main__':
    main()
# Original solution
from bisect import bisect_right

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)]

INF = 10 ** 9 + 1

li = []
for s, t, x in stx:
    li.append([s - x, 1, x])
    li.append([t - x, -1, x])

li.sort()
x_st = set([INF])
xxs = []
xs = [INF]

i = 0
for xx, check, x in li:
    if check == -1:
        x_st.remove(x)
    else:
        x_st.add(x)

    xxs.append(xx)
    xs.append(min(x_st))

for e in d:
    i = bisect_right(xxs, e)
    ans = xs[i]
    if ans == INF:
        ans = -1
    print(ans)


# Optimized solution
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")
# Original solution
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(eval(input()))
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,Q=LI()
HQ=[]
EVS=[]
for i in range(N):
    S,T,X=LI()
    EVS.append((S-0.5-X, 1, X))
    EVS.append((T-0.5-X, 0, X))
for i in range(Q):
    D=II()
    EVS.append((D, 2, D))
EVS.sort()

st=set()
PQ=[]
for time, ev, loc in EVS:
    if ev == 1:
        heapq.heappush(PQ, loc)
        st.add(loc)
    elif ev == 0:
        st.remove(loc)
    else:
        while PQ and PQ[0] not in st:
            heapq.heappop(PQ)
        if PQ:
            print((PQ[0]))
        else:
            print((-1))


# Optimized solution
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,Q=LI()
HQ=[]
EVS=[]
for i in range(N):
    S,T,X=LI()
    EVS.append((S-0.5-X, 1, X))
    EVS.append((T-0.5-X, 0, X))
for i in range(Q):
    D=II()
    EVS.append((D, 2, D))
EVS.sort()

st=set()
PQ=[]
for time, ev, loc in EVS:
    if ev == 1:
        heapq.heappush(PQ, loc)
        st.add(loc)
    elif ev == 0:
        st.remove(loc)
    else:
        while PQ and PQ[0] not in st:
            heapq.heappop(PQ)
        if PQ:
            print((PQ[0]))
        else:
            print((-1))
# Original solution
from heapq import heappush, heappop
n,q=map(int,input().split())
a=[]
for i in range(n):
  s,t,x=map(int,input().split())
  s-=x
  t-=x
  a.append([s,t,x])
a=sorted(a,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')



# Optimized solution
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')
# Original solution
from collections import deque

def BinarySearch(x,array):
    left=0
    right=len(array)-1

    while right-left>=0:
        mid=(left+right)//2
        if array[mid]==x:
            return mid
        elif array[mid]>x:
            right=mid-1
        else:
            left=mid+1
    return False


def main():
    ConstNum,PersonNum=list(map(int,input().split()))

    S=[]
    T=[]
    X=[]
    for i in range(ConstNum):
        s,t,x=list(map(int,input().split()))

        S.append(s-0.5)
        T.append(t-0.5)
        X.append(x)

    STX=list(zip(S,T,X))
    STX=sorted(STX)
    S,T,X=list(zip(*STX))

    S=deque(S)
    T=deque(T)
    X=deque(X)

    PersonsDistance=[]
    for i in range(PersonNum):
        d=int(eval(input()))
        PersonsDistance.insert(0,-1*d)

    res=[]

    time=0

    PersonsIndexes=[i for i in range(PersonNum-1,-1,-1)]

    while len(PersonsIndexes)>0 and len(X)>0:
        start=S.popleft()
        end=T.popleft()
        x=X.popleft()


        if start<time<end:
            underPerson=BinarySearch(x,PersonsDistance)
            if underPerson!=False:
                res.append((PersonsIndexes.pop(underPerson),PersonsDistance.pop(underPerson)))
            S.appendleft(start)
            T.appendleft(end)
            X.appendleft(x)
        elif start>time:
            S.appendleft(start)
            T.appendleft(end)
            X.appendleft(x)
        else:
            continue

        time+=1
        PersonsDistance=list([x+1 for x in PersonsDistance])

    for i in PersonsIndexes:
        res.append((i,-1))

    res=sorted(res)

    for i in res:
        print((i[1]))

if __name__=="__main__":
    main()





# Optimized solution
from bisect import bisect_left

def main():
    ConstNum,PersonNum=list(map(int,input().split()))

    S=[]
    T=[]
    X=[]
    for i in range(ConstNum):
        s,t,x=list(map(int,input().split()))
        S.append(s)
        T.append(t)
        X.append(x)

    DepartureTime=[]
    for i in range(PersonNum):
        d=int(eval(input()))
        DepartureTime.append(d)

    XST=list(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]))

if __name__=="__main__":
    main()
# Original solution
from heapq import heappop, heappush

N, Q = map(int, input().split())
event_list = []
for i in range(N):
  s, t, x = map(int, input().split())
  event_list.append([s-x, 1, x])
  event_list.append([t-x, -1, x])

for i in range(Q):
  event_list.append([int(input()), 2, 0])

ans = []
event_list.sort()
x_set = set()
x_list = []
for time, event, x in event_list:
  if event == 1:
    x_set.add(x)
    heappush(x_list, x)
  elif event == -1:
    x_set.remove(x)
  else:
    while x_list and x_list[0] not in x_set:
      heappop(x_list)
    if x_list:
      ans.append(x_list[0])
    else:
      ans.append(-1)

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


# Optimized solution
import sys
from heapq import heappop, heappush

input = sys.stdin.readline
N, Q = map(int, input().split())
event_list = []
for i in range(N):
  s, t, x = map(int, input().split())
  event_list.append([s-x, 1, x])
  event_list.append([t-x, -1, x])

for i in range(Q):
  event_list.append([int(input()), 2, 0])

ans = []
event_list.sort()
x_set = set()
x_list = []
for time, event, x in event_list:
  if event == 1:
    x_set.add(x)
    heappush(x_list, x)
  elif event == -1:
    x_set.remove(x)
  else:
    while x_list and x_list[0] not in x_set:
      heappop(x_list)
    if x_list:
      ans.append(x_list[0])
    else:
      ans.append(-1)

print(*ans, sep='\n')
# Original solution
from heapq import heappop,heappush
from collections import defaultdict
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,2,x))

for i in range(Q):
    d = int(eval(input()))
    event.append((d,3,i))
event.sort()

memo = defaultdict(int)
nowStop = []
ans = [-1]*Q
while event:
    t,e,x = heappop(event)
    if e == 1:
        heappush(nowStop,x)
        memo[x] += 1
    if e == 2:
        memo[x] -= 1
    if e == 3:
        while nowStop:
            s = nowStop[0]
            if memo[s] == 0:
                heappop(nowStop)
            else:
                ans[x] = s
                break
for a in ans:
    print(a)

# Optimized solution
from heapq import heappop,heappush
from collections import defaultdict
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,2,x))

for i in range(Q):
    d = int(eval(input()))
    event.append((d,3,i))
event.sort()

memo = defaultdict(int)
nowStop = []
ans = [-1]*Q
for t,e,x in event:
    if e == 1:
        heappush(nowStop,x)
        memo[x] += 1
    if e == 2:
        memo[x] -= 1
    if e == 3:
        while nowStop:
            s = nowStop[0]
            if memo[s] == 0:
                heappop(nowStop)
            else:
                ans[x] = s
                break
for a in ans:
    print(a)
# Original solution
import sys
class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res
#from bisect import bisect_left as bl
input = sys.stdin.readline

n,Q=list(map(int,input().split()))
xs = []
ts = set()
qs = []
for _ in range(n):
    s,t,x=list(map(int,input().split()))
    xs += [(s-x-0.4,True,x), (t-x-0.5,False,x)]
    ts.add(x)
for _ in range(Q):
    xs.append((int(eval(input())), 2, 0))
xs.sort(key=lambda x:x[0])

mx,XN = 10**9,len(ts)
x2i = {x:i for i,x in enumerate(ts)}
st = SegTree([mx]*XN, XN, mx, min)
for t,r,x in xs:
    if r == 2:
        c = st.query(0,XN)
        print((c if c!= mx else -1))
    else:
        st.update(x2i[x], x if r else mx)


# Optimized solution
import sys
n,Q=list(map(int,input().split()))
b_num = 2**(n-1).bit_length()
mx = 10**9
segl=[mx]*2*b_num 

def update( k, x):
    k += b_num-1
    segl[k] = x
    while k+1:
        k = (k-1)//2
        segl[k] = min(segl[k*2+1],segl[k*2+2])
    
def query():
    p = b_num-1
    q = n+b_num-2
    res=mx
    while q-p>1:
        if p&1 == 0:
            res = min(res,segl[p])
        if q&1 == 1:
            res = min(res,segl[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = min(res,segl[p])
    else:
        res = min(min(res,segl[p]),segl[q])
    return res

input = sys.stdin.readline

xs = []
for i in range(n):
    s,t,x=list(map(int,input().split()))
    xs += [(s-x-0.4,True,x,i), (t-x-0.5,False,x,i)]
for _ in range(Q):
    xs.append((int(eval(input())),2))
xs.sort(key=lambda x:x[0])

for x in xs:
    if x[1]==2:
        c = query()
        print((c if c!= mx else -1))
        continue
    update(x[3], x[2] if x[1] else mx)
# Original solution
import sys
n,Q=list(map(int,input().split()))
b_num = 2**(n-1).bit_length()
mx = 10**9
segl=[mx]*2*b_num 

def update( k, x):
    k += b_num-1
    segl[k] = x
    while k+1:
        k = (k-1)//2
        segl[k] = min(segl[k*2+1],segl[k*2+2])
    
def query():
    p = b_num-1
    q = n+b_num-2
    res=mx
    while q-p>1:
        if p&1 == 0:
            res = min(res,segl[p])
        if q&1 == 1:
            res = min(res,segl[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = min(res,segl[p])
    else:
        res = min(min(res,segl[p]),segl[q])
    return res

input = sys.stdin.readline

xs = []
for i in range(n):
    s,t,x=list(map(int,input().split()))
    xs += [(s-x-0.4,True,x,i), (t-x-0.5,False,x,i)]
for _ in range(Q):
    xs.append((int(eval(input())),2))
xs.sort(key=lambda x:x[0])

for x in xs:
    if x[1]==2:
        c = query()
        print((c if c!= mx else -1))
        continue
    update(x[3], x[2] if x[1] else mx)


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

n,Q=list(map(int,input().split()))
b_num = 2**(n-1).bit_length()
mx = 10**9
segl=[mx]*2*b_num 

def update( k, x):
    k += b_num-1
    segl[k] = x
    while k+1:
        k = (k-1)//2
        segl[k] = min(segl[k*2+1],segl[k*2+2])
    
def query():
    p = b_num-1
    q = n+b_num-2
    res=mx
    while q-p>1:
        if p&1 == 0:
            res = min(res,segl[p])
        if q&1 == 1:
            res = min(res,segl[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = min(res,segl[p])
    else:
        res = min(min(res,segl[p]),segl[q])
    return res


if __name__ == '__main__':
    xs = []
    for i in range(n):
        s,t,x=list(map(int,input().split()))
        xs += [(s-x-0.4,True,x,i), (t-x-0.5,False,x,i)]
    for _ in range(Q):
        xs.append((int(eval(input())),2))
    xs.sort(key=lambda x:x[0])
    for x in xs:
        if x[1]==2:
            c = query()
            print((c if c!= mx else -1))
            continue
        update(x[3], x[2] if x[1] else mx)
# Original solution
import sys
input = sys.stdin.readline

n,Q=list(map(int,input().split()))
b_num = 2**(n-1).bit_length()
mx = 10**9
segl=[mx]*2*b_num 

def update( k, x):
    k += b_num-1
    segl[k] = x
    while k+1:
        k = (k-1)//2
        segl[k] = min(segl[k*2+1],segl[k*2+2])
    
def query():
    p = b_num-1
    q = n+b_num-2
    res=mx
    while q-p>1:
        if p&1 == 0:
            res = min(res,segl[p])
        if q&1 == 1:
            res = min(res,segl[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = min(res,segl[p])
    else:
        res = min(min(res,segl[p]),segl[q])
    return res


if __name__ == '__main__':
    xs = []
    for i in range(n):
        s,t,x=list(map(int,input().split()))
        xs += [(s-x-0.4,True,x,i), (t-x-0.5,False,x,i)]
    for _ in range(Q):
        xs.append((int(eval(input())),2))
    xs.sort(key=lambda x:x[0])
    for x in xs:
        if x[1]==2:
            c = query()
            print((c if c!= mx else -1))
            continue
        update(x[3], x[2] if x[1] else mx)


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

n,Q=list(map(int,input().split()))
b_num = 2**(n-1).bit_length()
mx = 10**9
segl=[mx]*2*b_num 

def update( k, x):
    k += b_num-1
    segl[k] = x
    while k+1:
        k = (k-1)//2
        segl[k] = min(segl[k*2+1],segl[k*2+2])
    
if __name__ == '__main__':
    xs = []
    for i in range(n):
        s,t,x=list(map(int,input().split()))
        xs += [(s-x-0.4,True,x,i), (t-x-0.5,False,x,i)]
    for _ in range(Q):
        xs.append((int(eval(input())),2))
    xs.sort(key=lambda x:x[0])
    for x in xs:
        if x[1]==2:
            print((segl[0] if segl[0]!= mx else -1))
            continue
        update(x[3], x[2] if x[1] else mx)
# Original solution
import sys
input = sys.stdin.readline

n,Q=list(map(int,input().split()))
b_num = 2**(n-1).bit_length()
mx = 10**9
segl=[mx]*2*b_num 

def update(k, x):
    k += b_num-1
    segl[k] = x
    while k+1:
        k = (k-1)//2
        segl[k] = min(segl[k*2+1],segl[k*2+2])
    
if __name__ == '__main__':
    xs = []
    for i in range(n):
        s,t,x=list(map(int,input().split()))
        xs += [(s-x-0.4,True,x,i), (t-x-0.5,False,x,i)]
    for _ in range(Q):
        xs.append((int(eval(input())),2))
    xs.sort()
    for x in xs:
        if x[1]==2:
            print((segl[0] if segl[0]!= mx else -1))
            continue
        update(x[3], x[2] if x[1] else mx)


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

n,Q=list(map(int,input().split()))
b_num = 2**(n-1).bit_length()
mx = 10**9
segl=[mx]*2*b_num 

def update(k, x):
    k += b_num-1
    segl[k] = x
    while k+1:
        k = (k-1)//2
        segl[k] = min(segl[k*2+1],segl[k*2+2])
    
if __name__ == '__main__':
    xs = []
    for i in range(n):
        s,t,x=list(map(int,input().split()))
        xs += [(s-x-0.4,True,x,i), (t-x-0.5,False,x,i)]
    for _ in range(Q):
        xs.append((int(eval(input())),2))
    xs.sort(key=lambda x:x[0])
    for x in xs:
        if x[1]==2:
            print((segl[0] if segl[0]!= mx else -1))
            continue
        update(x[3], x[2] if x[1] else mx)