#include <bits/stdc++.h>
using namespace std;
typedef struct shivam {
  int l, r, w;
} shivam;
shivam s[1000004];
int color[1000004];
int amount[1000004];
int dp[6003];
int hash1[1000003];
char str1[1000004];
char str2[1000003];
vector<int> v1, v2, v3, diff[1000003], minicost[1000003], temp;
int tempo[1000003];
int cmp(shivam a, shivam b) {
  if (a.l < b.l) {
    return 1;
  } else if (a.l == b.l) {
    if (a.r < b.r) return 1;
    return 0;
  }
  return 0;
}
int main() {
  int i, j, k, l, m, n, t, a, b, c, x, y, z;
  int n1, n2;
  cin >> n >> x;
  for (i = 0; i < n; i++) {
    cin >> s[i].l >> s[i].r >> s[i].w;
  }
  sort(s, s + n, cmp);
  for (i = 0; i < n; i++) {
    v1.push_back(s[i].l);
    v2.push_back(s[i].r);
    v3.push_back(s[i].w);
  }
  for (i = n - 1; i >= 0; i--) {
    if (diff[s[i].r - s[i].l + 1].size() == 0) {
      temp.push_back(s[i].r - s[i].l + 1);
    }
    diff[s[i].r - s[i].l + 1].push_back(i);
  }
  for (i = 0; i < temp.size(); i++) {
    int ele = temp[i];
    sort(diff[ele].begin(), diff[ele].end());
    tempo[diff[ele].size() - 1] = s[diff[ele][diff[ele].size() - 1]].w;
    for (j = diff[ele].size() - 2; j >= 0; j--) {
      tempo[j] = min(tempo[j + 1], s[diff[ele][j]].w);
    }
    for (j = 0; j <= diff[ele].size() - 1; j++) {
      minicost[ele].push_back(tempo[j]);
    }
  }
  int mini = INT_MAX;
  for (i = 0; i < n; i++) {
    int ele = s[i].r;
    y = x - (s[i].r - s[i].l + 1);
    int g = upper_bound(v1.begin(), v1.end(), ele) - v1.begin();
    if (s[i].r == 3) {
    }
    if (diff[y].size() != 0) {
      int h = lower_bound(diff[y].begin(), diff[y].end(), g) - diff[y].begin();
      if (h < minicost[y].size()) mini = min(mini, minicost[y][h] + s[i].w);
    }
  }
  if (mini != INT_MAX)
    cout << mini << endl;
  else
    cout << "-1" << endl;
}
