#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > v[200005];
pair<pair<long long int, long long int>, long long int> vac[200005];
long long int n, x, l, r, c;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int i, j, k, ans;
  cin >> n >> x;
  for (i = 1; i <= n; i++) {
    cin >> l >> r >> c;
    vac[i].first.first = l;
    vac[i].first.second = r;
    vac[i].second = c;
    v[r - l + 1].push_back({l, c});
  }
  for (i = 0; i <= 200000; i++) {
    sort(v[i].begin(), v[i].end());
    long long int val;
    if (v[i].size()) {
      val = (v[i].back()).second;
      for (j = v[i].size() - 1; j >= 0; j--) {
        val = min(val, v[i][j].second);
        v[i][j].second = val;
      }
    }
  }
  long long int cst = 1e15;
  for (i = 1; i <= n; i++) {
    l = vac[i].first.first;
    r = vac[i].first.second;
    c = vac[i].second;
    j = r - l + 1;
    if (j <= x) {
      long long int rem = x - j;
      if (v[rem].size()) {
        pair<long long int, long long int> mp = {r + 1, 0};
        auto it = lower_bound(v[rem].begin(), v[rem].end(), mp);
        if (it != v[rem].end()) {
          cst = min(cst, c + (*it).second);
        }
      }
    }
  }
  if (cst == 1e15) cst = -1;
  cout << cst;
  return 0;
}
