#include <bits/stdc++.h>
const int N = 200005;
const int inf = 1e9;
inline void cmin(int& x, int y) {
  if (y < x) x = y;
}
int ed, ans, g[N], f[N], vis[N];
struct E {
  int v, nxt;
} e[N];
struct S {
  int l, r, c;
  int len() { return r - l + 1; }
  bool operator<(const S& a) const { return l < a.l; }
} s[N];
inline void adde(int x, int y) {
  e[++ed].v = y;
  e[ed].nxt = g[x];
  g[x] = ed;
}
int main() {
  int i, j, p, x, n;
  scanf("%d%d", &n, &x);
  for (i = 1; i <= n; ++i) {
    scanf("%d%d%d", &s[i].l, &s[i].r, &s[i].c);
    if (s[i].len() >= x) {
      --i;
      --n;
    }
  }
  std::sort(s + 1, s + 1 + n);
  p = 1;
  ans = inf << 1 | 1;
  for (i = 1; i < x; ++i) f[i] = inf;
  for (i = 1; i <= n; ++i) {
    for (; p < s[i].l; ++p) {
      for (j = g[p]; j; j = e[j].nxt) {
        cmin(f[s[e[j].v].len()], s[e[j].v].c);
        vis[s[e[j].v].len()] = 1;
      }
    }
    if (vis[x - s[i].len()]) cmin(ans, s[i].c + f[x - s[i].len()]);
    adde(s[i].r, i);
  }
  if (ans == (inf << 1 | 1)) ans = -1;
  printf("%d", ans);
  return 0;
}
