#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e16;
const int maxn = 1e6 + 5;
int n, x;
long long money[maxn];
struct node {
  int st, ed, cost, time, flag;
} a[maxn];
int cmp(node aa, node bb) {
  if (aa.st == bb.st)
    return aa.flag > bb.flag;
  else
    return aa.st < bb.st;
}
bool check(node aa, node bb) {
  if (aa.st < bb.st && aa.ed > bb.st)
    return 0;
  else if (aa.st < bb.st && aa.ed > bb.ed)
    return 0;
  else if (bb.st < aa.st && bb.ed > aa.st)
    return 0;
  else if (bb.st < aa.st && bb.ed > aa.ed)
    return 0;
  else if (bb.st == aa.st || bb.st == aa.ed || bb.ed == aa.st || bb.ed == aa.ed)
    return 0;
  if (aa.time + bb.time != x) return 0;
  return 1;
}
int main() {
  while (cin >> n >> x) {
    int cas = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[cas].st >> a[cas].ed >> a[cas].cost;
      a[cas].time = a[cas].ed - a[cas].st + 1;
      a[cas].flag = 1;
      cas++;
      a[cas].st = a[cas - 1].ed;
      a[cas].ed = -1;
      a[cas].flag = -1;
      a[cas].time = a[cas - 1].time;
      a[cas].cost = a[cas - 1].cost;
      cas++;
    }
    for (int i = 0; i <= x; i++) {
      money[i] = INF;
    }
    long long ans = INF;
    sort(a, a + cas, cmp);
    for (int i = 0; i < cas; i++) {
      if (a[i].flag == 1) {
        if (x - a[i].time > 0)
          ans = min(ans, money[x - a[i].time] + (long long)a[i].cost);
      } else {
        money[a[i].time] = min(money[a[i].time], (long long)a[i].cost);
      }
    }
    if (ans == INF)
      cout << "-1" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
