#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
vector<pair<int, int> > a[200010], b[200010];
int c[200010];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    a[x].push_back({y - x + 1, z});
    b[y].push_back({y - x + 1, z});
  }
  int ans = 2e9 + 10;
  memset(c, INF, sizeof(c));
  for (int i = 1; i <= 200000; i++) {
    for (int j = 0; j < a[i].size(); j++) {
      if (a[i][j].first >= k)
        continue;
      else if (c[k - a[i][j].first] != INF) {
        ans = min(ans, c[k - a[i][j].first] + a[i][j].second);
      }
    }
    for (int j = 0; j < b[i].size(); j++) {
      c[b[i][j].first] = min(c[b[i][j].first], b[i][j].second);
    }
  }
  if (ans != 2e9 + 10)
    printf("%d\n", ans);
  else
    printf("-1\n");
  return 0;
}
