#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  vector<vector<pair<long long, long long> > > left(200005);
  vector<vector<pair<long long, long long> > > right(200005);
  long long n, x;
  cin >> n >> x;
  long long minima[200005];
  for (long long i = 0; i < 200005; i++) minima[i] = 2e15;
  long long ans = 2e11;
  for (long long i = 0; i < n; i++) {
    long long l, r, x;
    cin >> l >> r >> x;
    left[l].push_back(make_pair(r - l + 1, x));
    right[r].push_back(make_pair(r - l + 1, x));
  }
  for (long long i = 1; i <= 200005; i++) {
    for (auto it : left[i]) {
      if (it.first >= x) continue;
      ans = min(ans, it.second + minima[x - it.first]);
    }
    for (auto it : right[i]) {
      minima[it.first] = min(minima[it.first], it.second);
    }
  }
  if (ans == 2e11) {
    cout << -1;
    return 0;
  }
  cout << ans;
}
