#include <bits/stdc++.h>
using namespace std;
struct v {
  int l;
  int r;
  int cost;
};
const long long int INF = 2000000001;
const int SIZE = 200001;
vector<v> sortL;
vector<v> sortR;
long long int arr[SIZE];
int n, x;
bool CompareL(const v& a, const v& b) { return a.l < b.l; }
bool CompareR(const v& a, const v& b) { return a.r < b.r; }
long long int min(long long int a, long long int b) { return a < b ? a : b; }
int main() {
  v tmp;
  long long int ans = INF;
  scanf("%d %d", &n, &x);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &tmp.l, &tmp.r, &tmp.cost);
    sortL.push_back(tmp);
    sortR.push_back(tmp);
  }
  sort(sortL.begin(), sortL.end(), CompareL);
  sort(sortR.begin(), sortR.end(), CompareR);
  for (int i = 0; i < SIZE; i++) arr[i] = INF;
  int idx = 0;
  v first = sortR[0];
  for (int i = 0; i < sortL.size(); i++) {
    v second = sortL[i];
    while (first.r < second.l) {
      int length = first.r - first.l + 1;
      arr[length] = min(arr[length], (long long int)first.cost);
      idx++;
      if (idx == sortR.size()) break;
      first = sortR[idx];
    }
    if (x < second.r - second.l + 1) continue;
    ans = min(ans, second.cost + arr[x - (second.r - second.l + 1)]);
  }
  if (ans >= INF)
    printf("-1\n");
  else
    printf("%d\n", ans);
}
