#include <bits/stdc++.h>
using namespace std;
void printvec(vector<pair<pair<int, int>, int> >& vec) {
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i].first.first << " " << vec[i].first.second << " "
         << vec[i].second << "\n";
  }
  cout << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  int n, dur;
  cin >> n >> dur;
  int i;
  vector<vector<pair<pair<int, int>, int> > > vec(3 * 100 * 1000),
      vec2(3 * 100 * 1000);
  for (i = 0; i < n; i++) {
    int l, r, cost;
    cin >> l >> r >> cost;
    int tim = r - l + 1;
    pair<pair<int, int>, int> temp = make_pair(make_pair(l, r), cost);
    vec[tim].push_back(temp);
    vec2[tim].push_back(temp);
  }
  int j;
  for (i = 0; i < vec.size(); i++) {
    sort(vec[i].begin(), vec[i].end());
    sort(vec2[i].begin(), vec2[i].end());
  }
  for (i = 0; i < vec2.size(); i++) {
    vector<pair<pair<int, int>, int> >& prev = vec2[i];
    int minn = INT_MAX;
    int sz = prev.size();
    for (j = sz - 1; j >= 0; j--) {
      minn = min(minn, prev[j].second);
      prev[j].second = minn;
    }
  }
  int ans = INT_MAX;
  vector<pair<pair<int, int>, int> >::iterator it;
  for (i = 0; i < vec.size(); i++) {
    vector<pair<pair<int, int>, int> >& prev = vec[i];
    int sz = prev.size();
    for (j = 0; j < sz; j++) {
      int prec = prev[j].second;
      int endt = prev[j].first.second;
      int left = dur - i;
      if (left < 0) continue;
      pair<pair<int, int>, int> temp = make_pair(make_pair(endt + 1, 0), 0);
      it = lower_bound(vec2[left].begin(), vec2[left].end(), temp);
      if (it == vec2[left].end()) continue;
      int extrac = it->second;
      if (ans > prec + extrac) {
        ans = prec + extrac;
      }
    }
  }
  if (ans == INT_MAX)
    cout << "-1";
  else
    cout << ans;
  return 0;
}
