#include <bits/stdc++.h>
using namespace std;
struct p {
  int r;
  int l;
  long long cost;
};
p vou[1000000];
pair<int, int> a[1000000];
int main() {
  std::ios::sync_with_stdio(false);
  long long n, x;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> vou[i].l >> vou[i].r >> vou[i].cost;
    a[i].first = vou[i].r;
    a[i].second = i;
  }
  sort(a, a + n);
  map<int, set<pair<int, long long> > > m;
  long long co = 1000000000000;
  for (int i = n - 1; i >= 0; i--) {
    p p1 = vou[a[i].second];
    int w = p1.r - p1.l + 1;
    if (x - w > 0 && m.find(x - w) != m.end()) {
      set<pair<int, long long> >::iterator it =
          m[x - w].lower_bound(make_pair(p1.r + 1, 0));
      pair<int, long long> ans = *it;
      long long co1 = 1000000000000;
      int f = 0;
      long long co2;
      while (it != m[x - w].end()) {
        ans = *it;
        f = 1;
        long long ans1 = ans.second + p1.cost;
        if (ans1 < co1) {
          co1 = ans1;
          co2 = ans.second;
        }
        if (ans1 < co) {
          co = ans1;
        }
        it++;
        m[x - w].erase(ans);
      }
      if (f) {
        m[x - w].insert(make_pair(200001, co2));
      }
    }
    if (m.find(w) != m.end()) {
      m[w].insert(make_pair(p1.l, p1.cost));
    } else {
      set<pair<int, long long> > s1;
      s1.insert(make_pair(p1.l, p1.cost));
      m[w] = s1;
    }
  }
  if (co <= 2000000000)
    cout << co;
  else
    cout << -1;
}
