#include <bits/stdc++.h>
using namespace std;
int n, x;
long long f[200010];
vector<pair<int, long long> > ke[200010];
struct te {
  int l, r;
  long long s;
} a[200010];
bool cmp(te i, te j) { return ((i.l < j.l) || (i.l == j.l && i.r < j.r)); }
int main() {
  if (fopen("a.txt", "r")) {
    freopen("a.txt", "r", stdin);
  } else
    ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> x;
  for (int i = 1; i <= n; i++) cin >> a[i].l >> a[i].r >> a[i].s;
  sort(a + 1, a + n + 1, cmp);
  int cur = 0;
  for (int i = 0; i <= x; i++) f[i] = (1LL << 61);
  long long res = (1LL << 61);
  for (int i = 1; i <= n; i++) {
    while (cur < a[i].l - 1) {
      cur++;
      for (auto tmp : ke[cur]) {
        f[tmp.first] = min(f[tmp.first], tmp.second);
      }
    }
    if (x > a[i].r - a[i].l + 1)
      res = min(res, a[i].s + f[x - a[i].r + a[i].l - 1]);
    ke[a[i].r].push_back(make_pair(a[i].r - a[i].l + 1, a[i].s));
  }
  if (res >= (1LL << 61)) res = -1;
  cout << res;
}
