#include <bits/stdc++.h>
using namespace std;
const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1};
const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1};
const double pi = acos(-1.0);
const int N = 2e5;
const int INF = 2e9 + 10;
struct abc {
  int l, r, cost;
};
int n, x, dp[N], ans = INF;
vector<abc> open[N + 100], close[N + 100];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> x;
  abc temp;
  for (int i = 1; i <= n; i++) {
    cin >> temp.l >> temp.r >> temp.cost;
    open[temp.l].push_back(temp);
    close[temp.r].push_back(temp);
  }
  int len;
  for (int i = 1; i <= N; i++) {
    while (!open[i].empty()) {
      temp = open[i].back();
      open[i].pop_back();
      len = temp.r - temp.l + 1;
      if (x >= len) {
        if (dp[x - len] > 0) ans = min(ans, dp[x - len] + temp.cost);
      }
    }
    while (!close[i].empty()) {
      temp = close[i].back();
      close[i].pop_back();
      len = temp.r - temp.l + 1;
      if (dp[len] == 0)
        dp[len] = temp.cost;
      else
        dp[len] = min(dp[len], temp.cost);
    }
  }
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
