Problem:
Score : 500 points

Problem Statement

There is an infinitely long street that runs west to east, which we consider as a number line.

There are N roadworks scheduled on this street.
The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.

Q people are standing at coordinate 0. The i-th person will start the coordinate 0 at time D_i, continue to walk with speed 1 in the positive direction and stop walking when reaching a blocked point.

Find the distance each of the Q people will walk.

Constraints

All values in input are integers.

1 \leq N, Q \leq 2 \times 10^5

0 \leq S_i < T_i \leq 10^9

1 \leq X_i \leq 10^9

0 \leq D_1 < D_2 < ... < D_Q \leq 10^9

If i \neq j and X_i = X_j, the intervals [S_i, T_i) and [S_j, T_j) do not overlap.

Input

Input is given from Standard Input in the following format:

N Q
S_1 T_1 X_1
:
S_N T_N X_N
D_1
:
D_Q

Output

Print Q lines. The i-th line should contain the distance the i-th person will walk or -1 if that person walks forever.

Sample Input 1

4 6
1 3 2
7 13 10
18 20 13
3 4 2
0
1
2
3
5
8

Sample Output 1

2
2
10
-1
13
-1

The first person starts coordinate 0 at time 0 and stops walking at coordinate 2 when reaching a point blocked by the first roadwork at time 2.

The second person starts coordinate 0 at time 1 and reaches coordinate 2 at time 3. The first roadwork has ended, but the fourth roadwork has begun, so this person also stops walking at coordinate 2.

The fourth and sixth persons encounter no roadworks while walking, so they walk forever. The output for these cases is -1.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

template<typename T>
class BIT{
public:
	int n;
	vector<T> dat;
	T init;
public:
	BIT(int x){
		n = x;
		init = 0; //書き換えする
		dat = vector<T>(n+1);
		for(int i = 0; i < n+1; i++){
			dat[i] = init;
		}
		return;
	}

	inline T func(T x, T y){
		return x + y; //書き換えする
	}

	T query(int i){ //[0,i)へのクエリ
		T s = 0;
		while(i > 0){
			s = func(s, dat[i]);
			i -= i&-i;
		}
		return s;
	}

	void add(int i, T x){
		i++;
		while(i <= n){
			dat[i] = func(dat[i],x);
			i += i & -i;
		}
	}
};


int main()
{
	ios_init();
	int n, q;
	while(cin >> n >> q) {
		vector<LL> s(n);
		vector<LL> t(n);
		vector<LL> x(n);
		REP(i, n) {
			cin >> s[i] >> t[i] >> x[i];
			s[i] -= x[i];
			t[i] -= x[i];
		}
		vector<LL> d(q);
		REP(i, q) cin >> d[i];
		
		vector<int> za(n);
		REP(i, n) {
			za[i] = x[i];
		}
		sort(ALL(za));
		za.erase(std::unique(za.begin(), za.end()), za.end());
		// REP(i, n) x[i] = lower_bound(ALL(za), x[i]) - za.begin();

		using P = pair<LL, LL>;
		LL INF = 1000000000000000LL;
		vector<P> qu;
		REP(i, n) {
			DEBUG(s[i]); DEBUG(t[i]);
			qu.emplace_back(s[i], x[i]);
			qu.emplace_back(t[i], -x[i]);
		}
		REP(i, q) {
			qu.emplace_back(d[i], INF);
		}
		sort(ALL(qu));
		dpite(ALL(qu));

		BIT<int> bit(SZ(za));
		vector<int> ans;
		REP(i, SZ(qu)) {
			DEBUG(i);
			DEBUG(qu[i]);
			// DEBUG(i);
			if(qu[i].S == INF) {
				// DEBUG(i); dpite(ALL(bit.dat));
				int l = 0;
				int r = SZ(za);
				if(bit.query(r) == 0) {
					l = n;
				} else {
					while(l + 1 < r) {
						int m = (l+r) / 2;
						if(bit.query(m) == 0) {
							l = m;
						} else {
							r = m;
						}
					}

				}
				if(l == n) {
					ans.push_back(-1);
				} else {
					ans.push_back(x[l]);
				}
			} else {
				if(qu[i].S < 0) {
					int idx = lower_bound(ALL(za), -qu[i].S) - za.begin();
					DEBUG(idx);
					bit.add(idx, -1);
				} else {
					int idx = lower_bound(ALL(za), qu[i].S) - za.begin();
					bit.add(idx, 1);
				}
			}
			REP(i, SZ(za)+1) {
				DEBUG(bit.query(i));
			}
		}
		REP(i, SZ(ans)) {
			cout << ans[i] << endl;
		}
	}
	return 0;
}