#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
const int INF = (int)2e9 + 10;
int ans = INF;
int n;
vector<pair<int, int>> a[N], b[N];
int c[N];
int d;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < N; i++) c[i] = INF;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int l, r, w;
    cin >> l >> r >> w;
    a[l].push_back(make_pair(r - l + 1, w));
    b[r].push_back(make_pair(r - l + 1, w));
  }
  for (int i = 0; i < N; i++) {
    for (auto t : a[i]) {
      if (t.first >= d) continue;
      if (c[d - t.first] < INF) ans = min(ans, c[d - t.first] + t.second);
    }
    for (auto t : b[i]) c[t.first] = min(c[t.first], t.second);
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
