#include <bits/stdc++.h>
using namespace std;
long long mincost[200005];
int n, x;
struct node {
  int l;
  int r;
  long long cost;
};
bool cmp1(node a, node b) { return a.l < b.l; }
bool cmp2(node a, node b) { return a.r < b.r; }
int main() {
  cin >> n >> x;
  node Leave[n], Back[n];
  int i, j = 0;
  for (i = 0; i < n; i++) {
    cin >> Leave[i].l >> Leave[i].r >> Leave[i].cost;
    Back[i] = Leave[i];
  }
  sort(Leave, Leave + n, cmp1);
  sort(Back, Back + n, cmp2);
  for (i = 0; i < 200005; i++) mincost[i] = 2e9 + 5;
  long long initmin = 2e9 + 5;
  for (i = 0; i < n; i++) {
    while (j < n && Back[j].r < Leave[i].l) {
      mincost[Back[j].r - Back[j].l + 1] =
          min(mincost[Back[j].r - Back[j].l + 1], Back[j].cost);
      j++;
    }
    int rest = x - (Leave[i].r - Leave[i].l + 1);
    if (rest > 0) {
      initmin = min(initmin, mincost[rest] + Leave[i].cost);
    }
  }
  if (initmin == 2e9 + 5)
    cout << "-1" << endl;
  else
    cout << initmin << endl;
}
