#include <bits/stdc++.h>
using namespace std;
void update(int, int, int, int, int, int, int);
long long int query(int, int, int, int, int, int, int);
int l[200001], r[200001], c[200001];
pair<int, int> tree[2][10000001];
vector<int> v[200001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, x, i, j;
  long long int ans = 1000000000000;
  cin >> n >> x;
  for (i = 0; i < n; i++) {
    cin >> l[i] >> r[i] >> c[i];
    v[r[i] - l[i] + 1].push_back(i);
  }
  for (i = 1; i < x; i++) {
    for (j = 0; j < v[i].size(); j++) {
      if (x - i == i) {
        ans = min(ans, c[v[x - i][j]] + query(1, 1, 200000, r[v[x - i][j]] + 1,
                                              200000, 0, i));
        ans = min(ans, c[v[x - i][j]] +
                           query(1, 1, 200000, 1, l[v[x - i][j]] - 1, 1, i));
      }
      update(1, 1, 200000, l[v[i][j]], c[v[i][j]], 0, i);
      update(1, 1, 200000, r[v[i][j]], c[v[i][j]], 1, i);
    }
    if (x - i != i) {
      for (j = 0; j < v[x - i].size(); j++) {
        ans = min(ans, c[v[x - i][j]] + query(1, 1, 200000, r[v[x - i][j]] + 1,
                                              200000, 0, i));
        ans = min(ans, c[v[x - i][j]] +
                           query(1, 1, 200000, 1, l[v[x - i][j]] - 1, 1, i));
      }
    }
  }
  if (ans >= 1000000000000)
    cout << -1 << "\n";
  else
    cout << ans << "\n";
  return 0;
}
void update(int node, int st, int en, int id, int val, int fid, int d) {
  if (st == en) {
    if (tree[fid][node].second == d)
      tree[fid][node].first = min(tree[fid][node].first, val);
    else
      tree[fid][node] = {val, d};
    return;
  }
  int mid = (st + en) / 2;
  if (id <= mid)
    update(2 * node, st, mid, id, val, fid, d);
  else
    update(2 * node + 1, mid + 1, en, id, val, fid, d);
  if (tree[fid][node].second == d) {
    if (tree[fid][2 * node].second == d)
      tree[fid][node].first =
          min(tree[fid][node].first, tree[fid][2 * node].first);
    if (tree[fid][2 * node + 1].second == d)
      tree[fid][node].first =
          min(tree[fid][node].first, tree[fid][2 * node + 1].first);
  } else {
    if (tree[fid][2 * node].second == d)
      tree[fid][node].first = tree[fid][2 * node].first;
    else
      tree[fid][node].first = tree[fid][2 * node + 1].first;
    tree[fid][node].second = d;
  }
}
long long int query(int node, int st, int en, int l, int r, int fid, int d) {
  if (r < st || en < l || r < l) return 1000000000000;
  if (tree[fid][node].second != d) return 1000000000000;
  if (l <= st && en <= r) return tree[fid][node].first;
  int mid = (st + en) / 2;
  long long int p1 = query(2 * node, st, mid, l, r, fid, d);
  long long int p2 = query(2 * node + 1, mid + 1, en, l, r, fid, d);
  return min(p1, p2);
}
