#include <bits/stdc++.h>
using namespace std;
const int md = 2e5 + 10;
const long long INF = 1e15;
struct node {
  long long l, r, w;
};
bool cmp(const node& a, const node& b) { return (a.l < b.l); }
bool operator<(node a, node b) { return (a.r > b.r); }
priority_queue<node> heap;
node a[md];
long long n, x, res;
long long ans[md];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> x;
  for (long long i = 1; i <= n; i++) cin >> a[i].l >> a[i].r >> a[i].w;
  res = INF;
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 0; i <= md; i++) ans[i] = INF;
  for (long long i = 1; i <= n; i++) {
    while (!heap.empty() && heap.top().r < a[i].l) {
      node cur = heap.top();
      heap.pop();
      ans[cur.r - cur.l + 1] = min(ans[cur.r - cur.l + 1], cur.w);
    }
    long long k = x - (a[i].r - a[i].l + 1);
    if (k < 0) continue;
    res = min(res, a[i].w + ans[k]);
    heap.push(a[i]);
  }
  if (res == INF)
    cout << -1;
  else
    cout << res;
}
