#include <bits/stdc++.h>
using namespace std;
int N, X;
int Min;
set<int> has;
map<int, int> cand;
vector<pair<int, int> > In[200005], Out[200005];
int mxt = 200000;
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> X;
  int Li, Ri, Ci;
  for (int i = 1; i <= N; i++) {
    cin >> Li >> Ri >> Ci;
    In[Li].push_back(make_pair(Ci, Ri - Li + 1));
    Out[Ri + 1].push_back(make_pair(Ci, Ri - Li + 1));
  }
  int Di;
  bool fnd = 0;
  Min = 2e9 + 5;
  for (int t = 1; t <= mxt; t++) {
    for (pair<int, int> pi : Out[t]) {
      Ci = pi.first, Di = pi.second;
      if (has.find(Di) == has.end()) {
        has.insert(Di);
        cand[Di] = Ci;
      } else {
        cand[Di] = min(cand[Di], Ci);
      }
    }
    for (pair<int, int> pi : In[t]) {
      Ci = pi.first, Di = pi.second;
      if (has.find(X - Di) == has.end()) continue;
      fnd = 1;
      Min = min(Min, Ci + cand[X - Di]);
    }
  }
  cout << (fnd ? Min : -1) << '\n';
}
