#include <bits/stdc++.h>
using namespace std;
struct vac {
  int l, r, cost, duration;
  vac() : cost(-1) {}
  vac(int l, int r, int cost) : l(l), r(r), cost(cost), duration(r - l + 1) {}
};
vector<vector<vac> > lifes(200001, vector<vac>(0)),
    deaths(200001, vector<vac>(0));
vector<vac> cheapest(200001);
int min1(int x, int y) {
  if (x == -1) return y;
  if (y == -1) return x;
  return min(x, y);
}
int main() {
  int n, x;
  cin >> n >> x;
  int minAns = -1;
  for (int i = 0; i < n; i++) {
    int l, r, cost;
    cin >> l >> r >> cost;
    lifes[l].push_back(vac(l, r, cost));
    deaths[r].push_back(vac(l, r, cost));
  }
  for (int i = 0; i < lifes.size(); i++) {
    for (int j = 0; j < lifes[i].size(); j++) {
      int d = lifes[i][j].duration;
      if (d > x) continue;
      if (cheapest[x - d].cost != -1)
        minAns = min1(minAns, cheapest[x - d].cost + lifes[i][j].cost);
    }
    for (int j = 0; j < deaths[i].size(); j++) {
      int d = deaths[i][j].duration;
      cheapest[d].cost = min1(cheapest[d].cost, deaths[i][j].cost);
    }
  }
  cout << minAns << endl;
}
