#include <bits/stdc++.h>
const long long INF = 1e18;
using namespace std;
struct w {
  int d, cost;
};
const int MAXN = 200000 + 20;
vector<w> ll[MAXN], rr[MAXN];
w W[MAXN];
long long c[MAXN];
int main() {
  int n, x;
  while (~scanf("%d%d", &n, &x)) {
    long long ans = INF;
    for (int i = 0; i <= 200000; i++) c[i] = INF;
    int tx, ty, tz;
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d", &tx, &ty, &tz);
      W[i].d = ty - tx + 1;
      W[i].cost = tz;
      ll[tx].push_back(W[i]);
      rr[ty].push_back(W[i]);
    }
    for (int i = 1; i <= 200000; i++) {
      for (int j = 0; j < ll[i].size(); j++) {
        int t = ll[i][j].d;
        if (x - t >= 0) ans = min(ans, c[x - t] + ll[i][j].cost);
      }
      for (int j = 0; j < rr[i].size(); j++) {
        c[rr[i][j].d] = min(c[rr[i][j].d], (long long)rr[i][j].cost);
      }
    }
    if (ans == INF)
      puts("-1");
    else
      printf("%64d\n", ans);
  }
  return 0;
}
