#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
vector<pair<int, int> > con[200005], con2[200005];
int N, X;
void solve(int xxx) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> X;
  int a, b, c;
  for (int i = 0; i < N; i++) {
    cin >> a >> b >> c;
    con2[a].push_back(pair<int, int>(b - a + 1, c));
    con[b + 1].push_back(pair<int, int>(b - a + 1, c));
  }
  int ans = 2000000009;
  map<int, int> mp;
  for (int i = 0; i < 200005; i++) {
    for (int j = 0; j < con[i].size(); j++) {
      if (mp[con[i][j].first])
        mp[con[i][j].first] = min(mp[con[i][j].first], con[i][j].second);
      else
        mp[con[i][j].first] = con[i][j].second;
    }
    for (int j = 0; j < con2[i].size(); j++) {
      if (mp[X - con2[i][j].first]) {
        ans = min(ans, con2[i][j].second + mp[X - con2[i][j].first]);
      }
    }
  }
  cout << (ans == 2000000009 ? -1 : ans) << endl;
  return;
}
int main() {
  int T;
  T = 1;
  for (int i = 0; i < T; i++) solve(i + 1);
  return (0);
}
