#include <bits/stdc++.h>
using namespace std;
struct node {
  long long int r, len, c;
  friend bool operator<(node a, node b) { return a.r > b.r; }
};
struct cd {
  long long int l, r, c;
};
long long int mi[200005];
const long long int inf = 3000000000;
vector<cd> v;
bool cmp(cd a, cd b) {
  if (a.l == b.l) return a.r < b.r;
  return a.l < b.l;
}
int main() {
  long long int n, x;
  while (cin >> n >> x) {
    long long int a, b, c;
    long long int ans = inf;
    v.clear();
    fill(mi, mi + 200000, inf);
    priority_queue<node> upt;
    for (long long int i = 0; i < n; i++) {
      cin >> a >> b >> c;
      v.push_back((cd){a, b, c});
    }
    sort(v.begin(), v.end(), cmp);
    for (int i = 0; i < v.size(); i++) {
      while (!upt.empty()) {
        node check = upt.top();
        if (v[i].l <= check.r) break;
        upt.pop();
        if (mi[check.len] > check.c) mi[check.len] = check.c;
      }
      cd now = v[i];
      long long int len = now.r - now.l + 1;
      long long int f = x - len;
      upt.push((node){now.r, len, now.c});
      if (f <= 0) continue;
      if (now.c + mi[f] < ans) ans = now.c + mi[f];
    }
    if (ans != inf)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
