#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, long long> > p[200010];
vector<vector<int> > v;
vector<vector<long long> > cost;
vector<int> node;
map<int, int> mp;
int main() {
  int n, x;
  cin >> n >> x;
  v.resize(2 * 1e5 + 1);
  cost.resize(2 * 1e5 + 1);
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second.first >> p[i].second.second;
  }
  sort(p, p + n);
  for (int i = 0; i < n; i++) {
    int l = p[i].first;
    int r = p[i].second.first;
    int d = p[i].second.second;
    if (mp[r - l + 1] == 0) {
      node.push_back(r - l + 1);
    }
    mp[r - l + 1]++;
    v[r - l + 1].push_back(l);
    cost[r - l + 1].push_back(d);
  }
  for (int i = 0; i < node.size(); i++) {
    long long res = 1e18;
    for (int j = v[node[i]].size() - 1; j >= 0; j--) {
      cost[node[i]][j] = min(res, cost[node[i]][j]);
      res = min(res, cost[node[i]][j]);
    }
  }
  long long res = 1e18;
  for (int i = 0; i < n; i++) {
    int cost1 = p[i].second.first - p[i].first + 1;
    int ser = x - cost1;
    if (ser >= 0) {
      int d = upper_bound(v[ser].begin(), v[ser].end(), p[i].second.first) -
              v[ser].begin();
      if (d != v[ser].size()) {
        res = min(p[i].second.second + cost[ser][d], res);
      }
    }
  }
  if (res == 1e18)
    cout << -1;
  else
    cout << res;
  return 0;
}
