#include <bits/stdc++.h>
const int inf = (2e9) + 2;
using namespace std;
vector<pair<pair<int, int>, pair<int, long long> > > q;
int l[200005], r[200005], c[200005];
long long best[200005];
int main() {
  q.clear();
  int n, x;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i] >> c[i];
    q.push_back(make_pair(make_pair(l[i], -1), make_pair(r[i], c[i])));
    q.push_back(make_pair(make_pair(r[i], 1), make_pair(l[i], c[i])));
  }
  long long ans = inf;
  for (int i = 0; i < 200005; i++) best[i] = inf;
  sort(q.begin(), q.end());
  for (int i = 0; i < q.size(); i++) {
    if (q[i].first.second == -1) {
      int l = q[i].second.first - q[i].first.first + 1;
      if (l <= x) ans = min(ans, q[i].second.second + best[x - l]);
    }
    if (q[i].first.second == 1) {
      int l = q[i].first.first - q[i].second.first + 1;
      best[l] = min(best[l], q[i].second.second);
    }
  }
  if (ans >= inf) ans = -1;
  cout << ans << endl;
  return 0;
}
