#include <bits/stdc++.h>
using namespace std;
template <class T>
inline int chkmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline int chkmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
const int INF = (int)2e9 + 15;
const long long LINF = (long long)1e18;
const int maxn = 200000 + 15;
struct Data {
  int l, r, cost;
  Data(int l = 0, int r = 0, int cost = 0) : l(l), r(r), cost(cost) {}
  bool operator<(const Data &other) const {
    if (l == other.l) return r < other.r;
    return l < other.l;
  }
};
int n, x;
vector<Data> a[maxn];
vector<int> f[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> x;
  for (int i = (1), _b = (n); i <= _b; ++i) {
    int l, r, cost;
    cin >> l >> r >> cost;
    a[r - l + 1].push_back(Data(l, r, cost));
  }
  for (int i = (0), _b = (maxn - 1); i <= _b; ++i)
    if (int((a[i]).size())) sort((a[i]).begin(), (a[i]).end());
  for (int i = (0), _b = (maxn - 1); i <= _b; ++i)
    if (int((a[i]).size())) {
      for (int j = (0), _b = (int((a[i]).size()) - 1); j <= _b; ++j)
        f[i].push_back(0);
      f[i][int((a[i]).size()) - 1] = a[i].back().cost;
      for (int j = (int((a[i]).size()) - 2), _b = (0); j >= _b; --j)
        f[i][j] = min(f[i][j + 1], a[i][j].cost);
    }
  int ans = INF;
  for (int i = (0), _b = (maxn - 1); i <= _b; ++i)
    if (int((a[i]).size())) {
      int y = x - i;
      if (0 <= y && y < maxn && int((a[y]).size())) {
        for (int j = (0), _b = (int((a[i]).size()) - 1); j <= _b; ++j) {
          int l = a[i][j].l, r = a[i][j].r, cost = a[i][j].cost;
          int lo = 0, hi = int((a[y]).size()) - 1, p = -1;
          while (lo <= hi) {
            int mi = (lo + hi) / 2;
            if (a[y][mi].l > r) {
              p = mi;
              hi = mi - 1;
            } else
              lo = mi + 1;
          }
          if (p == -1) continue;
          chkmin(ans, cost + f[y][p]);
        }
      }
    }
  if (ans >= INF)
    cout << -1;
  else
    cout << ans;
  return 0;
}
