#include <bits/stdc++.h>
using namespace std;
int l[200005];
int r[200005];
int c[200005];
vector<pair<int, int>> v;
int done[200005];
const int inf = 2000000005;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, z;
  cin >> n >> z;
  for (int i = 0; i <= 200002; i++) done[i] = inf;
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i] >> c[i];
    v.push_back({l[i], -i});
    v.push_back({r[i], i});
  }
  sort(v.begin(), v.end());
  int ans = inf;
  for (auto x : v) {
    int ind = x.second;
    if (ind < 0) {
      ind = -ind;
      int len = r[ind] - l[ind] + 1;
      if (len <= z && done[z - len] != inf) {
        ans = min(ans, c[ind] + done[z - len]);
      }
    } else {
      int len = r[ind] - l[ind] + 1;
      if (len <= z) done[len] = min(done[len], c[ind]);
    }
  }
  if (ans == inf)
    cout << -1;
  else
    cout << ans;
}
