from ctypes import *

import subprocess as sp

from operator import itemgetter

import sys

import os.path



set_code = r"""

#include <set>



std::set<int> s;



void add(int x) {

    s.insert(x);

}



bool find(int x) {

    return s.find(x) != s.end();

}



void remove(int x) {

    s.erase(x);

}



bool empty() {

	return s.empty();

}



int getMin() {

	return *s.begin();

}

"""



class CppSet:

	counter = 0



	def __init__(self):

		lib_name = './hoge{}.so'.format(CppSet.counter)



		if not os.path.exists(lib_name):

			code_file_name = "tmp.cpp"

			with open(code_file_name, "w") as f:

				f.write(set_code)



			CppSet.counter += 1

			sp.Popen(['g++', '-fPIC', '-shared', '-std=c++11', code_file_name, '-o', lib_name]).communicate()



		lib = CDLL(lib_name)

		self.add = getattr(lib, "_Z3addi")

		self.find = CFUNCTYPE(c_bool, c_int)(

						("_Z4findi", lib),

						((1, "x"), )

					)

		self.remove = getattr(lib, "_Z6removei")

		self.empty = CFUNCTYPE(c_bool)(

						("_Z5emptyv", lib),

						()

					)



		self.getMin = CFUNCTYPE(c_int)(

						("_Z6getMinv", lib),

						()

					)



def main():

	N, Q = map(int, sys.stdin.readline().split())

	tmp = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]

	stx = [(s - x, 1, x) for s, t, x in tmp] + [(t - x, -1, x) for s, t, x in tmp]

	stx.sort()

	

	D = [int(sys.stdin.readline()) for _ in range(Q)] 

	ans = [-1]*Q



	idx = 0

	stx_len = len(stx)

	se = CppSet()

	for i, d in enumerate(D):

		while idx < stx_len:

			t, com, x = stx[idx]

			if t > d:

				break

			if com == 1:

				se.add(x)

			else:

				se.remove(x)

			idx += 1

		ans[i] = (-1 if se.empty() else se.getMin())



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



if __name__ == "__main__":

	main()

from ctypes import *

import subprocess as sp

from operator import itemgetter

import sys

import os.path



set_code = r"""

#include <set>



std::set<int> s;



void add(int x) {

    s.insert(x);

}



bool find(int x) {

    return s.find(x) != s.end();

}



void remove(int x) {

    s.erase(x);

}



bool empty() {

	return s.empty();

}



int getMin() {

	return *s.begin();

}

"""



class CppSet:

	counter = 0



	def __init__(self):

		lib_name = './hoge{}.so'.format(CppSet.counter)



		code_file_name = "tmp.cpp"

		with open(code_file_name, "w") as f:

			f.write(set_code)



		CppSet.counter += 1

		sp.Popen(['g++', '-fPIC', '-shared', '-std=c++11', code_file_name, '-o', lib_name]).communicate()



		lib = CDLL(lib_name)

		self.add = getattr(lib, "_Z3addi")

		self.find = CFUNCTYPE(c_bool, c_int)(

						("_Z4findi", lib),

						((1, "x"), )

					)

		self.remove = getattr(lib, "_Z6removei")

		self.empty = CFUNCTYPE(c_bool)(

						("_Z5emptyv", lib),

						()

					)



		self.getMin = CFUNCTYPE(c_int)(

						("_Z6getMinv", lib),

						()

					)



def main():

	N, Q = map(int, sys.stdin.readline().split())

	tmp = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]

	stx = [(s - x, 1, x) for s, t, x in tmp] + [(t - x, -1, x) for s, t, x in tmp]

	stx.sort()

	

	D = [int(sys.stdin.readline()) for _ in range(Q)] 

	ans = [-1]*Q



	idx = 0

	stx_len = len(stx)

	se = CppSet()

	for i, d in enumerate(D):

		while idx < stx_len:

			t, com, x = stx[idx]

			if t > d:

				break

			if com == 1:

				se.add(x)

			else:

				se.remove(x)

			idx += 1

		ans[i] = (-1 if se.empty() else se.getMin())



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



if __name__ == "__main__":

	main()

from ctypes import *
import subprocess as sp
from operator import itemgetter
import sys
import os.path

set_code = r"""
#include <set>
std::set<int> s;
void add(int x) {
    s.insert(x);
}
bool find(int x) {
    return s.find(x) != s.end();
}
void remove(int x) {
    s.erase(x);
}
bool empty() {
	return s.empty();
}
int getMin() {
	return *s.begin();
}
"""


class CppSet:
    counter = 0

    def __init__(self):
        lib_name = "./hoge{}.so".format(CppSet.counter)
        if not os.path.exists(lib_name):
            code_file_name = "tmp.cpp"
            with open(code_file_name, "w") as f:
                f.write(set_code)
            CppSet.counter += 1
            sp.Popen(
                [
                    "g++",
                    "-fPIC",
                    "-shared",
                    "-std=c++11",
                    code_file_name,
                    "-o",
                    lib_name,
                ]
            ).communicate()
        lib = CDLL(lib_name)
        self.add = getattr(lib, "_Z3addi")
        self.find = CFUNCTYPE(c_bool, c_int)(("_Z4findi", lib), ((1, "x"),))
        self.remove = getattr(lib, "_Z6removei")
        self.empty = CFUNCTYPE(c_bool)(("_Z5emptyv", lib), ())
        self.getMin = CFUNCTYPE(c_int)(("_Z6getMinv", lib), ())


def main():
    N, Q = map(int, sys.stdin.readline().split())
    tmp = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
    stx = [(s - x, 1, x) for s, t, x in tmp] + [(t - x, -1, x) for s, t, x in tmp]
    stx.sort()
    D = [int(sys.stdin.readline()) for _ in range(Q)]
    ans = [-1] * Q
    idx = 0
    stx_len = len(stx)
    se = CppSet()
    for i, d in enumerate(D):
        while idx < stx_len:
            t, com, x = stx[idx]
            if t > d:
                break
            if com == 1:
                se.add(x)
            else:
                se.remove(x)
            idx += 1
        ans[i] = -1 if se.empty() else se.getMin()
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

from ctypes import *
import subprocess as sp
from operator import itemgetter
import sys
import os.path

set_code = r"""
#include <set>
std::set<int> s;
void add(int x) {
    s.insert(x);
}
bool find(int x) {
    return s.find(x) != s.end();
}
void remove(int x) {
    s.erase(x);
}
bool empty() {
	return s.empty();
}
int getMin() {
	return *s.begin();
}
"""


class CppSet:
    counter = 0

    def __init__(self):
        lib_name = "./hoge{}.so".format(CppSet.counter)
        code_file_name = "tmp.cpp"
        with open(code_file_name, "w") as f:
            f.write(set_code)
        CppSet.counter += 1
        sp.Popen(
            ["g++", "-fPIC", "-shared", "-std=c++11", code_file_name, "-o", lib_name]
        ).communicate()
        lib = CDLL(lib_name)
        self.add = getattr(lib, "_Z3addi")
        self.find = CFUNCTYPE(c_bool, c_int)(("_Z4findi", lib), ((1, "x"),))
        self.remove = getattr(lib, "_Z6removei")
        self.empty = CFUNCTYPE(c_bool)(("_Z5emptyv", lib), ())
        self.getMin = CFUNCTYPE(c_int)(("_Z6getMinv", lib), ())


def main():
    N, Q = map(int, sys.stdin.readline().split())
    tmp = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
    stx = [(s - x, 1, x) for s, t, x in tmp] + [(t - x, -1, x) for s, t, x in tmp]
    stx.sort()
    D = [int(sys.stdin.readline()) for _ in range(Q)]
    ans = [-1] * Q
    idx = 0
    stx_len = len(stx)
    se = CppSet()
    for i, d in enumerate(D):
        while idx < stx_len:
            t, com, x = stx[idx]
            if t > d:
                break
            if com == 1:
                se.add(x)
            else:
                se.remove(x)
            idx += 1
        ans[i] = -1 if se.empty() else se.getMin()
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

-        if not os.path.exists(lib_name): -            code_file_name = "tmp.cpp" -            with open(code_file_name, "w") as f: -                f.write(set_code) -            CppSet.counter += 1 -            sp.Popen( -                [ -                    "g++", -                    "-fPIC", -                    "-shared", -                    "-std=c++11", -                    code_file_name, -                    "-o", -                    lib_name, -                ] -            ).communicate() +        code_file_name = "tmp.cpp" +        with open(code_file_name, "w") as f: +            f.write(set_code) +        CppSet.counter += 1 +        sp.Popen( +            ["g++", "-fPIC", "-shared", "-std=c++11", code_file_name, "-o", lib_name] +        ).communicate()