#include <bits/stdc++.h>
using namespace std;
int l[200000];
int r[200000];
int c[200000];
vector<int> l_sort;
vector<int> r_sort;
long long int best[200001];
int left_order(int a, int b) { return l[a] < l[b]; }
int right_order(int a, int b) { return r[a] < r[b]; }
int main() {
  int i, n, x;
  scanf("%d%d", &n, &x);
  for (i = 0; i < n; ++i) {
    scanf("%d%d%d", l + i, r + i, c + i);
    l_sort.push_back(i);
    r_sort.push_back(i);
  }
  sort(l_sort.begin(), l_sort.end(), left_order);
  sort(r_sort.begin(), r_sort.end(), right_order);
  for (i = 1; i <= 200000; ++i) {
    best[i] = 2134567890;
  }
  int j = 0;
  long long int mn = 2134567890;
  for (i = 0; i < n; ++i) {
    int now = l_sort[i];
    while (j < n && r[r_sort[j]] < l[now]) {
      int now2 = r_sort[j];
      best[r[now2] - l[now2] + 1] =
          min(best[r[now2] - l[now2] + 1], static_cast<long long int>(c[now2]));
      ++j;
    }
    int y = x - (r[now] - l[now] + 1);
    if (y > 0) {
      mn = min(mn, c[now] + best[y]);
    }
  }
  printf("%lld\n", mn >= 2134567890 ? -1LL : mn);
  return 0;
}
