#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using llu = unsigned long long;
ll mod = 1e9 + 7;
ll mode = 998244353;
vector<pair<ll, ll>> l[200001], r[200001];
ll c[200001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t, n, m, i, j, k;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    ll x, y, z;
    cin >> x >> y >> z;
    l[x].push_back({y - x + 1, z});
    r[y].push_back({y - x + 1, z});
  }
  for (i = 0; i <= 200000; i++) {
    c[i] = INT_MAX;
  }
  ll ans = INT_MAX;
  for (i = 1; i <= 200000; i++) {
    for (auto y : l[i]) {
      if (y.first >= m) continue;
      ans = min(ans, y.second + c[m - y.first]);
    }
    for (auto y : r[i]) {
      c[y.first] = min(c[y.first], y.second);
    }
  }
  if (ans == INT_MAX)
    cout << -1;
  else
    cout << ans;
}
