#include <bits/stdc++.h>
using namespace std;
void FastInputOutput() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void ReadFromFile() { freopen("in.txt", "r", stdin); }
int D() {
  int t;
  scanf("%d", &t);
  return t;
}
long long LLD() {
  long long t;
  scanf("%lld", &t);
  return t;
}
char C() {
  char c;
  scanf("%c", &c);
  return c;
}
const int N = 2e5 + 5;
vector<pair<int, int> > all[N];
vector<int> mi[N];
vector<pair<int, pair<int, int> > > a;
bool cpm(pair<int, int> s, pair<int, int> f) { return (f.first > s.first); }
int main() {
  int TCF = 1;
  ;
  while (TCF--) {
    int n = D(), x = D();
    for (int i = 0; i < n; ++i) {
      int l = D(), r = D(), c = D();
      if (r - l + 1 > x) continue;
      all[r - l + 1].push_back({l, c});
      a.push_back({l, {r, c}});
    }
    for (int i = 0; i < N; ++i) {
      sort(all[i].begin(), all[i].end(), cpm);
      int sz = all[i].size();
      if (!sz) continue;
      vector<int> m(all[i].size());
      m[sz - 1] = all[i][sz - 1].second;
      for (int j = sz - 2; j >= 0; --j) m[j] = min(m[j + 1], all[i][j].second);
      mi[i] = m;
    }
    long long ans = LONG_LONG_MAX;
    for (int i = 0; i < a.size(); ++i) {
      int l = a[i].first, r = a[i].second.first, c = a[i].second.second;
      int res = x - (r - l + 1);
      if (res > 0 && all[res].size()) {
        pair<int, int> temp = {r, 0};
        int idx = upper_bound(all[res].begin(), all[res].end(), temp, cpm) -
                  all[res].begin();
        if (idx != all[res].size()) ans = min(ans, (long long)mi[res][idx] + c);
      }
    }
    printf("%lld\n", ans == LONG_LONG_MAX ? -1 : ans);
  }
  return 0;
}
