#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
typedef map<LL,LL>::iterator Itr;
LL MOD=1000000007;

struct S{
    LL x;LL y;LL z;
    bool operator<(const S&a)const{
        return x<a.x||(x==a.x&&y<a.y)||(x==a.x&&y==a.y&&z<a.z);
    }
    bool operator==(const S&a)const{
        return (x==a.x)&&(y==a.y)&&(z==a.z);
    }
};

int main()
{ 
    LL n,Q;
    cin>>n>>Q;
    vector<S> v;
    for(int i=0;i<n;i++){
        LL a,b,c;
        cin>>a>>b>>c;
        S s;
        s.x=c;s.y=a;s.z=b;
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());

    /*for(int i=0;i<v.size();i++){
        S s=v[i];
        cout<<s.x<<' '<<s.y<<' '<<s.z<<endl;
    }*/

    map<LL,LL> m;
    for(int i=0;i<Q;i++){
        LL a;
        cin>>a;
        m.insert(P(a,i));
    }
    LL ans[Q];
    for(int i=0;i<n;i++){
        S s=v.back();
        v.pop_back();
        LL begin=s.y-s.x;
        LL end=s.z-s.x;
        vector <LL>d;
        for(Itr itr=m.lower_bound(begin);itr!=m.lower_bound(end);advance(itr,1)){
            ans[(*itr).second]=s.x;
            d.push_back((*itr).first);
        }
        while(!d.empty()){m.erase(d.back());d.pop_back();}
    }
    for(Itr itr=m.begin();itr!=m.end();advance(itr,1)){
        ans[(*itr).second]=-1;
    }
    for(int i=0;i<Q;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#pragma region
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#pragma endregion

int N,T;
vector<pair<int,int>> p;
int dp[6666];
void solve()
{
    cin>>N>>T;
    p.resize(N);
    forn(i, N) cin>>p[i].f>>p[i].s;
    //
    sort(p.begin(), p.end());
    for(auto& it: p)
    {
        for (int now = T - 1; now>= 0; --now)
        {
            dp[now+it.f] = max(dp[now+it.f], dp[now] + it.s);
        }
    }
    int ans = 0;
    forn(i, 6666) ans = max(ans, dp[i]);
    cout << ans << '\n';
}

signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(22);
    // cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}
