#include <bits/stdc++.h>
using namespace std;
struct event {
  int x, size, val, ent;
  bool operator<(const event& rhs) const {
    if (x == rhs.x) return ent < rhs.ent;
    return x < rhs.x;
  }
};
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  int n, x;
  cin >> n >> x;
  vector<event> v;
  for (int i = 0; i < n; i++) {
    int l, r, cost;
    cin >> l >> r >> cost;
    v.push_back({l, r - l + 1, cost, 0});
    v.push_back({r, r - l + 1, cost, 1});
  }
  sort(v.begin(), v.end());
  int ans = 0x7fffffff;
  map<int, int> mp;
  for (const event& eve : v) {
    if (eve.ent == 0) {
      auto it = mp.find(x - eve.size);
      if (it == mp.end())
        continue;
      else
        ans = min(ans, it->second + eve.val);
    } else {
      if (mp[eve.size] == 0)
        mp[eve.size] = eve.val;
      else
        mp[eve.size] = min(eve.val, mp[eve.size]);
    }
  }
  if (ans == 0x7fffffff) ans = -1;
  cout << ans << "\n";
}
