#include <bits/stdc++.h>
using namespace std;
struct Voucher {
  int l, c, minfrom;
};
bool comparator(const Voucher &a, const Voucher &b) { return a.l < b.l; }
int main() {
  int n, x, money = int((long)(1 << 31) - 1l);
  unordered_map<int, vector<Voucher>> v;
  v.clear();
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    if (r - l + 1 < x) v[r - l + 1].push_back(Voucher{l, c});
  }
  for (auto i = v.begin(); i != v.end(); ++i) {
    sort(i->second.begin(), i->second.end(), comparator);
    int cm = int((long)(1 << 31) - 1l);
    for (auto j = i->second.rbegin(); j != i->second.rend(); ++j) {
      if (j->c < cm) cm = j->c;
      j->minfrom = cm;
    }
  }
  vector<int> o;
  for (auto &p : v) o.push_back(p.first);
  for (auto &oi : o) {
    auto &i = v[oi];
    for (auto j = i.begin(); j != i.end(); ++j) {
      auto from = lower_bound(v[x - oi].begin(), v[x - oi].end(),
                              Voucher{j->l + oi}, comparator);
      if (from != v[x - oi].end() && from->minfrom + j->c < money)
        money = from->minfrom + j->c;
    }
  }
  if (money == int((long)(1 << 31) - 1l)) money = -1;
  cout << money << endl;
  return 0;
}
