#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  vector<pair<int, int> > v[200020];
  for (int i = 0; i < n; i++) {
    int l, r, c;
    cin >> l >> r >> c;
    if (r - l + 1 > x) continue;
    v[r - l + 1].push_back(make_pair(l, c));
  }
  for (int i = 0; i <= x; i++) sort(v[i].begin(), v[i].end());
  int min1 = 2000000001;
  for (int d = 1; d < x; d++) {
    int temp = 2000000001;
    for (int i = 0, j = 0; i < v[x - d].size(); i++) {
      while (j < v[d].size() && v[d][j].first + d - 1 < v[x - d][i].first) {
        temp = min(temp, v[d][j].second);
        j++;
      }
      if (temp != 2000000001) min1 = min(min1, temp + v[x - d][i].second);
    }
  }
  if (min1 == 2000000001) {
    cout << -1;
  } else {
    cout << min1;
  }
  return 0;
}
