#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > done[200000 + 2];
vector<pair<int, int> > rc[200000 + 2];
int mp[200000 + 2];
int n, x;
int ans = INT_MAX;
int main() {
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    rc[l].push_back(make_pair(r, c));
  }
  for (int i = 1; i <= 200000; i++) {
    for (int j = 0; j < rc[i].size(); j++) {
      int r = rc[i][j].first, c = rc[i][j].second;
      if (r + 1 - i > x) continue;
      if (mp[x - (r + 1 - i)]) {
        ans = min(ans, c + mp[x - (r + 1 - i)]);
      }
      done[r].push_back(make_pair(r + 1 - i, c));
    }
    for (int j = 0; j < done[i].size(); j++) {
      int d = done[i][j].first, c = done[i][j].second;
      if (!mp[d] || mp[d] > c) mp[d] = c;
    }
  }
  if (ans == INT_MAX) ans = -1;
  cout << ans;
  return 0;
}
