#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
const long long inf = 1e12;
pair<int, int> que[N << 1];
int l[N], r[N];
long long dp[N], c[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, x;
  cin >> n >> x;
  for (int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i] >> c[i];
    que[2 * i - 2] = make_pair(l[i], -i);
    que[2 * i - 1] = make_pair(r[i], +i);
  }
  sort(que, que + 2 * n);
  fill(dp, dp + N, inf);
  long long ans = inf;
  for (int i = 0; i < 2 * n; i++) {
    int id = que[i].second;
    if (id < 0) {
      id = -id;
      int len = r[id] - l[id] + 1;
      if (len < x) {
        ans = min(ans, c[id] + dp[x - len]);
      }
    } else {
      int len = r[id] - l[id] + 1;
      dp[len] = min(dp[len], c[id]);
    }
  }
  if (ans == inf) ans = -1;
  cout << ans << '\n';
  return 0;
}
