#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int INF = (int)2e9 + 10;
typedef struct vocationn {
  int min_cost[N];
  vector<pair<int, int> > left[N];
  vector<pair<int, int> > right[N];
} vocation;
int n, x, cost, l, r, ans = INF;
vocation voc;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  for (int i = 0; i < N; i++) voc.min_cost[i] = INF;
  cin >> n >> x;
  for (size_t i = 0; i < n; i++) {
    cin >> l >> r >> cost;
    voc.left[l].push_back(pair<int, int>(r - l + 1, cost));
    voc.right[r].push_back(pair<int, int>(r - l + 1, cost));
  }
  for (int i = 0; i < N; i++) {
    for (pair<int, int> t : voc.left[i]) {
      if (t.first >= x) continue;
      if (voc.min_cost[x - t.first] < INF)
        ans = min(ans, voc.min_cost[x - t.first] + t.second);
    }
    for (pair<int, int> t : voc.right[i])
      voc.min_cost[t.first] = min(voc.min_cost[t.first], t.second);
  }
  if (ans == INF)
    cout << "-1" << endl;
  else
    cout << ans << endl;
  return 0;
}
