#include <bits/stdc++.h>
using namespace std;
struct plan {
  long long l, r;
  long long cost;
};
bool sorter(const plan& a, const plan& b) { return a.r < b.r; }
bool sorter2(const plan& a, const plan& b) {
  if (a.cost == b.cost)
    return a.l < b.l;
  else
    return a.cost < b.cost;
}
long long n, x;
plan ps[200020];
vector<plan> v[200020];
long long idx[200020];
int main() {
  cin.sync_with_stdio(false);
  cin >> n >> x;
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    ps[i] = (plan){a, b, c};
    v[b - a + 1].push_back((plan){a, b, c});
  }
  sort(ps, ps + n, sorter);
  for (long long i = (long long)(0); i < (long long)(200020); i++)
    sort((v[i]).begin(), (v[i]).end(), sorter2);
  long long res = 1e16;
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    long long l = ps[i].l, r = ps[i].r, cost = ps[i].cost;
    long long rest = x - (r - l + 1);
    if (rest < 0 || rest > 200000) continue;
    while (idx[rest] < v[rest].size()) {
      if (r < v[rest][idx[rest]].l)
        break;
      else
        idx[rest]++;
    }
    if (idx[rest] == v[rest].size()) continue;
    res =
        (res < cost + v[rest][idx[rest]].cost ? res
                                              : cost + v[rest][idx[rest]].cost);
  }
  if (res == 1e16)
    cout << -1 << endl;
  else
    cout << res << endl;
  return 0;
}
