#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long n, x;
  cin >> n >> x;
  vector<vector<pair<long, long>>> startWithDuration(2e5 + 1),
      endWithDuration(2e5 + 1);
  for (long i = 0; i < n; i++) {
    long l, r, c;
    cin >> l >> r >> c;
    startWithDuration[r - l + 1].push_back({l, c});
    endWithDuration[r - l + 1].push_back({r, c});
  }
  for (long i = 0; i < startWithDuration.size(); i++) {
    sort(startWithDuration[i].begin(), startWithDuration[i].end());
    sort(endWithDuration[i].begin(), endWithDuration[i].end());
  }
  long ans = -1;
  for (long x1 = 1; x1 < x; x1++) {
    if (endWithDuration[x1].size() > 0 &&
        startWithDuration[x - x1].size() > 0) {
      long i = 0;
      long j = 0;
      long minCost = endWithDuration[x1][0].second;
      while (j < startWithDuration[x - x1].size() &&
             startWithDuration[x - x1][j].first <= endWithDuration[x1][0].first)
        j++;
      for (; j < startWithDuration[x - x1].size(); j++) {
        while (i + 1 < endWithDuration[x1].size() &&
               endWithDuration[x1][i + 1].first <
                   startWithDuration[x - x1][j].first) {
          i++;
          minCost = min(minCost, endWithDuration[x1][i].second);
        }
        if (ans == -1 || ans > minCost + startWithDuration[x - x1][j].second) {
          ans = minCost + startWithDuration[x - x1][j].second;
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
