#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0;
  int x = 0;
  cin >> n >> x;
  vector<pair<int, pair<int, int>>> lefts;
  vector<pair<int, pair<int, int>>> rights;
  lefts.reserve(n);
  rights.reserve(n);
  for (int i = 0; i < n; ++i) {
    int left = 0;
    int right = 0;
    int cost = 0;
    cin >> left >> right >> cost;
    int const length = 1 + right - left;
    if (length < x) {
      lefts.emplace_back(left, make_pair(length, cost));
      rights.emplace_back(right, make_pair(length, cost));
    }
  }
  sort(begin(lefts), end(lefts));
  sort(begin(rights), end(rights));
  unordered_map<int, int> seen_length_to_costs;
  auto rights_it = begin(rights);
  int best_cost = numeric_limits<int>::max();
  for (auto const lefts_item : lefts) {
    while (rights_it->first < lefts_item.first) {
      auto seen_length_cost_it =
          seen_length_to_costs.find(rights_it->second.first);
      if (seen_length_cost_it != end(seen_length_to_costs)) {
        seen_length_cost_it->second =
            min(seen_length_cost_it->second, rights_it->second.second);
      } else {
        seen_length_to_costs[rights_it->second.first] =
            rights_it->second.second;
      }
      ++rights_it;
    }
    auto const matching_item_it =
        seen_length_to_costs.find(x - lefts_item.second.first);
    if (matching_item_it != end(seen_length_to_costs)) {
      best_cost =
          min(best_cost, matching_item_it->second + lefts_item.second.second);
    }
  }
  if (best_cost == numeric_limits<int>::max()) {
    cout << -1 << endl;
  } else {
    cout << best_cost << endl;
  }
}
