#include <bits/stdc++.h>
using namespace std;
typedef long long (*MY_FUNC)(long long x, long long y);
const long long MAX_LL = 1LL << 62;
const int MAX_INT = (int)((1LL << 31) - 1);
const double PI = acos(-1);
const double EPS = 0.0000001L;
const long long MOD = 1000000007;
typedef struct Voucher {
  long long l, r, c, d;
} Voucher;
long long n, x;
vector<Voucher> voucher1, voucher2;
vector<long long> best;
bool compare1(const Voucher& v1, const Voucher& v2) { return v1.l < v2.l; }
bool compare2(const Voucher& v1, const Voucher& v2) { return v1.r < v2.r; }
void solve() {
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    int l, r, c, d;
    cin >> l >> r >> c;
    d = r - l + 1;
    if (d < x) {
      voucher1.push_back((Voucher){l, r, c, d});
      voucher2.push_back((Voucher){l, r, c, d});
    }
  }
  sort(voucher1.begin(), voucher1.end(), compare1);
  sort(voucher2.begin(), voucher2.end(), compare2);
  best = vector<long long>(x, MAX_LL);
  long long i2 = 0, result = MAX_LL;
  for (int i1 = 0; i1 < voucher1.size(); i1++) {
    while (voucher2[i2].r < voucher1[i1].l) {
      best[voucher2[i2].d] = min(best[voucher2[i2].d], voucher2[i2].c);
      i2++;
    }
    result = min(result, voucher1[i1].c + best[x - voucher1[i1].d]);
  }
  cout << (result == MAX_LL ? -1 : result) << endl;
}
int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
