#include <bits/stdc++.h>
using namespace std;
struct s {
  int l, r, cost;
};
const int MAXN = 2e5 + 10;
int minn[MAXN], n, x, INF, ans, now;
s a[MAXN], b[MAXN];
bool cmp(s a, s b) {
  if (a.l < b.l) {
    return true;
  } else if (a.l == b.l && a.r < b.r) {
    return true;
  }
  return false;
}
bool cmp2(s a, s b) {
  if (a.r < b.r) {
    return true;
  }
  return false;
}
int main() {
  while (scanf("%d%d", &n, &x) != EOF) {
    for (int i = 1; i <= n; ++i) {
      scanf("%d%d%d", &a[i].l, &a[i].r, &a[i].cost);
      b[i] = a[i];
    }
    memset(minn, 0x7f, sizeof(minn));
    INF = minn[0];
    ans = INF;
    now = 1;
    sort(a + 1, a + 1 + n, cmp);
    sort(b + 1, b + 1 + n, cmp2);
    for (int i = 1; i <= n; ++i) {
      int num = (a[i].r - a[i].l + 1);
      int remain = x - num;
      while (now <= n && b[now].r < a[i].l) {
        minn[b[now].r - b[now].l + 1] =
            min(minn[b[now].r - b[now].l + 1], b[now].cost);
        ++now;
      }
      if (remain > 0 && minn[remain] != INF) {
        ans = min(ans, a[i].cost + minn[remain]);
      }
    }
    if (ans == INF) {
      printf("-1\n");
    } else {
      printf("%d\n", ans);
    }
  }
  return 0;
}
