#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void amin(T &x, const T &y) {
  if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class Iter>
void rprintf(const char *fmt, Iter begin, Iter end) {
  for (bool sp = 0; begin != end; ++begin) {
    if (sp)
      putchar(' ');
    else
      sp = true;
    printf(fmt, *begin);
  }
  putchar('\n');
}
int N, X;
struct Data {
  int l, r, c;
  bool operator<(const Data &y) const { return l < y.l; }
} D[200111];
struct CMP {
  bool operator()(const Data &x, const Data &y) const { return x.r > y.r; }
};
long long P[200111];
void MAIN() {
  scanf("%d%d", &N, &X);
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    int l, r, c;
    scanf("%d%d%d", &l, &r, &c);
    r++;
    D[i].l = l;
    D[i].r = r;
    D[i].c = c;
  }
  sort(D, D + N);
  memset(P, 0x3f, sizeof P);
  long long ans = P[0];
  priority_queue<Data, vector<Data>, CMP> Q;
  for (int i = 0; i < N; i++) {
    while (Q.size() && Q.top().r <= D[i].l) {
      Data d = Q.top();
      Q.pop();
      amin(P[d.r - d.l], (long long)d.c);
    }
    int k = X - (D[i].r - D[i].l);
    if (k > 0) {
      amin(ans, D[i].c + P[k]);
    }
    Q.push(D[i]);
  }
  if (ans == P[0]) ans = -1;
  printf("%lld\n", ans);
}
int main() {
  int TC = 1;
  for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN();
  return 0;
}
