#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
struct node {
  int l, r, cost;
} a[maxn], b[maxn];
bool cmp1(node a, node b) {
  if (a.l != b.l) return a.l < b.l;
  return a.r < b.r;
}
bool cmp2(node a, node b) {
  if (a.r != b.r) return a.r < b.r;
  return a.l < b.l;
}
map<int, int> M;
int main() {
  int n, x;
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].cost);
    b[i] = a[i];
  }
  sort(a + 1, a + 1 + n, cmp1);
  sort(b + 1, b + 1 + n, cmp2);
  int i = 1;
  int ans = 2e9 + 1;
  for (int j = 1; j <= n; j++) {
    while (b[i].r < a[j].l) {
      if (M.count(b[i].r - b[i].l + 1)) {
        M[b[i].r - b[i].l + 1] = min(M[b[i].r - b[i].l + 1], b[i].cost);
      } else
        M[b[i].r - b[i].l + 1] = b[i].cost;
      i++;
    }
    if (M.count(x - (a[j].r - a[j].l + 1)))
      ans = min(ans, M[x - (a[j].r - a[j].l + 1)] + a[j].cost);
  }
  if (ans == 2e9 + 1)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
