#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 100000 + 10;
const int inf = 0x7fffffff;
int n, m;
int MinCost[N];
struct node {
  int l, r, cost;
  bool operator<(const node &B) const { return r > B.r; }
} d[N];
bool cmp(const node A, const node B) { return A.l < B.l; }
priority_queue<node> que;
int solve() {
  int ans = inf;
  for (int i = 1; i <= m; i++) MinCost[i] = inf;
  for (int i = 1; i <= n; i++) {
    if (d[i].r - d[i].l + 1 >= m) continue;
    while (!que.empty() && que.top().r < d[i].l) {
      node A = que.top();
      que.pop();
      MinCost[A.r - A.l + 1] = min(A.cost, MinCost[A.r - A.l + 1]);
    }
    if (MinCost[m - (d[i].r - d[i].l + 1)] != inf)
      ans = min(ans, MinCost[m - (d[i].r - d[i].l + 1)] + d[i].cost);
    que.push(d[i]);
  }
  return ans == inf ? -1 : ans;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> d[i].l >> d[i].r >> d[i].cost;
  sort(d + 1, d + 1 + n, cmp);
  cout << solve() << endl;
  return 0;
}
