#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  map<int, set<pair<int, int> > > make_pair, mp1;
  pair<pair<int, int>, int> vc[n + 1];
  for (int i = 0; i < n; i++) {
    int l, r, cst;
    cin >> l >> r >> cst;
    vc[i].first.first = l;
    vc[i].first.second = r;
    vc[i].second = cst;
    make_pair[r - l + 1].insert({r, cst});
  }
  for (auto i : make_pair) {
    int tt = -1;
    for (set<pair<int, int> >::iterator st = i.second.begin();
         st != i.second.end(); st++) {
      if (tt == -1)
        tt = (*st).second;
      else
        tt = min(tt, (*st).second);
      mp1[i.first].insert({(*st).first, tt});
    }
  }
  int ans = INT_MAX;
  for (int i = 0; i < n; i++) {
    int tt = vc[i].first.second - vc[i].first.first + 1;
    tt = x - tt;
    if (mp1.count(tt)) {
      int l = vc[i].first.first;
      set<pair<int, int> >::iterator it = mp1[tt].lower_bound({l, 0});
      if (it != mp1[tt].begin()) {
        it--;
        ans = min(ans, (*it).second + vc[i].second);
      }
    }
  }
  if (ans != INT_MAX)
    cout << ans << "\n";
  else
    cout << "-1\n";
  return 0;
}
