#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long N = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const long long inf = -1e18;
long long c[2 * N + 10], ans = INF, l, r, a[2 * N], len[2 * N];
vector<long long> L[2 * N], R[2 * N];
int main() {
  long long n, h;
  cin >> n >> h;
  for (int i = 1; i <= n; i++) {
    cin >> l >> r >> a[i];
    L[l].push_back(i);
    R[r].push_back(i);
    len[i] = r - l + 1;
  }
  for (int i = 0; i <= 200000; i++) {
    c[i] = INF;
  }
  for (int i = 1; i <= 200000; i++) {
    for (int j = 0; j < L[i].size(); j++) {
      long long k = L[i][j];
      if (len[k] > h) {
        continue;
      }
      ans = min(ans, c[h - len[k]] + a[k]);
    }
    for (int j = 0; j < R[i].size(); j++) {
      long long k = R[i][j];
      if (len[k] > h) {
        continue;
      }
      c[len[k]] = min(c[len[k]], a[k]);
    }
  }
  if (ans < INF) {
    cout << ans;
  } else {
    cout << -1;
  }
  cin.get(), cin.get();
  return 0;
}
