#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int N = 2 * 1e5 + 10;
vector<pair<int, int> > T[N];
int main() {
  ios_base::sync_with_stdio(false);
  int n, x, l, r, cost;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> l >> r >> cost;
    T[r - l + 1].push_back(make_pair(l, cost));
  }
  for (int i = 0; i <= x; i++) sort(T[i].begin(), T[i].end());
  int ans = INF;
  for (int d = 1; d < x; d++) {
    int temp = INF;
    for (int i = 0, j = 0; i < T[x - d].size(); i++) {
      while (j < T[d].size() && T[d][j].first + d - 1 < T[x - d][i].first) {
        temp = min(temp, T[d][j].second);
        j++;
      }
      if (temp != INF) ans = min(ans, temp + T[x - d][i].second);
    }
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
