#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[200005];
vector<int> mi[200005];
struct compare {
  bool operator()(const pair<int, int>& l, const pair<int, int>& r) {
    return l.first < r.first;
  }
};
int main() {
  int t, k, i, j, n, m, x, y, q, c;
  int l, r;
  cin >> n >> x;
  for (i = 0; i < n; i++) {
    scanf("%d%d%d", &l, &r, &c);
    v[r - l + 1].push_back(make_pair(l, c));
  }
  for (i = 0; i < 200005; i++) {
    sort(v[i].begin(), v[i].end());
    m = 2e9;
    for (j = v[i].size() - 1; j >= 0; j--) {
      m = min(m, v[i][j].second);
      mi[i].push_back(m);
    }
    reverse(mi[i].begin(), mi[i].end());
  }
  int ans = 2e9 + 7;
  for (i = 1; i < 200005; i++)
    for (j = 0; j < v[i].size(); j++) {
      q = x - i;
      if (q >= 2e5 + 5 || q <= 0) continue;
      k = upper_bound(v[q].begin(), v[q].end(),
                      make_pair(v[i][j].first + i - 1, INT_MIN), compare()) -
          v[q].begin();
      if (k == v[q].size()) continue;
      ans = min(ans, v[i][j].second + mi[q][k]);
    }
  if (ans == 2e9 + 7)
    cout << -1;
  else
    cout << ans;
  return 0;
}
