#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
struct node {
  int l, r, cost;
} t[200010];
int x, n;
vector<int> v[200010];
vector<int> b[200010];
bool cmp(const int &x, const int &y) { return t[x].l < t[y].l; }
struct cmp_upper {
  bool operator()(int x, int index) { return t[index].l > x; }
};
int main() {
  scanf("%d%d", &n, &x);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &t[i].l, &t[i].r, &t[i].cost);
    v[t[i].r - t[i].l + 1].push_back(i);
  }
  for (int i = 1; i <= 200000; i++) {
    if (v[i].empty()) continue;
    sort(v[i].begin(), v[i].end(), cmp);
    b[i].resize(v[i].size() + 1);
    b[i][v[i].size()] = inf;
    for (int j = v[i].size() - 1; j >= 0; j--)
      b[i][j] = min(b[i][j + 1], t[v[i][j]].cost);
  }
  int ans = inf;
  for (int i = 1; i <= n; i++) {
    int tem = t[i].cost;
    int j = x - (t[i].r - t[i].l + 1);
    if (j <= 0 || v[j].empty()) continue;
    int k = upper_bound(v[j].begin(), v[j].end(), t[i].r, cmp_upper()) -
            v[j].begin();
    if (k < v[j].size()) {
      tem += b[j][k];
      if (tem < ans) ans = tem;
    }
  }
  if (ans == inf)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
