#include <bits/stdc++.h>   using namespace std;   template <class T>   void debug(T a, T b) {     ;   }   template <class T>   void chmin(T& a, const T& b) {     if (a > b) a = b;   }   template <class T>   void chmax(T& a, const T& b) {     if (a < b) a = b;   }   namespace std {   template <class S, class T>   ostream& operator<<(ostream& out, const pair<S, T>& a) {     out <<  (  << a.first <<  ,  << a.second <<  ) ;     return out;   }   }  // namespace std   long long int readL() {     long long int res;     scanf( %I64d , &res);     return res;   }   void printL(long long int res) { printf( %I64d , res); }   int n, S;   struct pack {     int in, out, w, s, v;   };   pack par[505];   bool cmp(const pack& a, const pack& b) {     return make_pair(a.in, -a.out) < make_pair(b.in, -b.out);   }   int tmp[1005][1005];   int dp[505][1005];   void renew(int i, int base) {     int lim = min(S, par[base].w + par[base].s);     for (int j = 0; j < (lim); ++j) {       chmax(tmp[i][j + 1], tmp[i][j]);     }   }   void update(pack p, int id, int base) {     int l = p.in, r = p.out;     renew(l, base);     int lim = min(S, par[base].w + par[base].s);     for (int i = (par[base].w); i < (lim + 1); ++i)       if (tmp[l][i] >= 0 && dp[id][i - par[base].w] >= 0) {         chmax(tmp[r][i], tmp[l][i] + dp[id][i - par[base].w]);       }   }   void bring(int i, int base) {     renew(i, base);     int lim = min(S, par[base].w + par[base].s);     for (int j = 0; j < (lim + 1); ++j) {       chmax(tmp[i + 1][j], tmp[i][j]);     }   }   int main() {     cin >> n >> S;     for (int i = 0; i < (n); ++i) {       cin >> par[i].in >> par[i].out >> par[i].w >> par[i].s >> par[i].v;     }     par[n] = (pack){0, 2 * n, 0, S + 1, 0};     ++n;     sort(par, par + n, cmp);     memset(dp, -1, sizeof(dp));     int res = 0;     for (int i = n - 1; i >= 0; --i) {       pack p = par[i];       int l = par[i].in, r = par[i].out;       for (int j = (l); j < (r + 1); ++j)         for (int k = 0; k < (S + 1); ++k) tmp[j][k] = -1;       tmp[l][p.w] = p.v;       renew(l, i);       int cur = l;       for (int j = (i + 1); j < (n); ++j) {         if (l <= par[j].in && par[j].out <= r) {           while (cur < par[j].in) {             bring(cur, i);             ++cur;           }           update(par[j], j, i);         }       }       while (cur < r) {         bring(cur, i);         ++cur;       }       renew(r, i);       int lim = min(S, p.w + p.s);       for (int j = 0; j < (lim + 1); ++j) {         dp[i][j] = tmp[r][j];         chmax(res, tmp[r][j]);       }       for (int j = 0; j < (S); ++j) chmax(dp[i][j + 1], dp[i][j]);     }     cout << res << endl;     return 0;   }   