#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return !b ? a : gcd(b, a % b);
}
template <typename T>
inline void umin(T &a, T b) {
  a = a < b ? a : b;
}
template <typename T>
inline void umax(T &a, T b) {
  a = a > b ? a : b;
}
const int N = (int)2e5 + 5;
const int INF = (int)2e9 + 7;
const long long MOD = (long long)1e9 + 7;
struct data {
  int l, r, w, minw;
  data(int _l, int _r, int _w) : l(_l), r(_r), w(_w), minw(_w) {}
  bool operator<(const data &x) const { return l == x.l ? r < x.r : l < x.l; }
};
vector<data> v[N];
int main() {
  int n, x;
  scanf("%d%d", &n, &x);
  for (int i = 1; i <= n; i++) {
    int l, r, w;
    scanf("%d%d%d", &l, &r, &w);
    v[r - l + 1].push_back({l, r, w});
  }
  for (int i = 1; i < N; i++) {
    sort(v[i].begin(), v[i].end());
  }
  for (int i = 1; i < N; i++) {
    for (int j = v[i].size() - 2; j >= 0; j--) {
      umin(v[i][j].minw, v[i][j + 1].minw);
    }
  }
  int res = INF;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      int l = v[i][j].l, r = v[i][j].r, w = v[i][j].w;
      int need = x - (r - l + 1);
      if (need < 0 or v[need].empty()) continue;
      int L = 0, R = v[need].size() - 1, F = -1;
      while (L <= R) {
        int M = (L + R) >> 1;
        if (v[need][M].l > r)
          F = M, R = M - 1;
        else
          L = M + 1;
      }
      if (~F) umin(res, w + v[need][F].minw);
    }
  }
  if (res == INF) res = -1;
  cout << res << '\n';
  return 0;
}
