#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
std::vector<pair<long long, long long> > v1[200005], v2[200005];
long long dp[200005];
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, x;
  cin >> n >> x;
  int l, r, m;
  for (int i = 0; i < n; ++i) {
    cin >> l >> r >> m;
    if (r - l + 1 >= x) continue;
    v1[l].push_back(make_pair(r - l + 1, m));
    v2[r].push_back(make_pair(r - l + 1, m));
  }
  long long ans = 100000000000;
  for (int i = 200000; i >= 0; i--) {
    for (int j = 0; j < v2[i].size(); j++) {
      if (dp[x - v2[i][j].first]) {
        ans = min(ans, dp[x - v2[i][j].first] + v2[i][j].second);
      }
    }
    for (int j = 0; j < v1[i].size(); j++) {
      if (dp[v1[i][j].first])
        dp[v1[i][j].first] = min(dp[v1[i][j].first], v1[i][j].second);
      else
        dp[v1[i][j].first] = v1[i][j].second;
    }
  }
  cout << (ans >= 100000000000 ? -1 : ans);
  return 0;
}
