#include <bits/stdc++.h>
using namespace std;
map<int, vector<pair<int, int>>> begmp, endmp;
int main() {
  int n, x;
  scanf(" %d %d", &(n), &(x));
  for (int i = 0; i < (n); ++i) {
    int x, y, c;
    scanf(" %d %d", &(x), &(y));
    scanf(" %d", &(c));
    int sz = y - x + 1;
    begmp[sz].push_back(make_pair(x, c));
    endmp[sz].push_back(make_pair(y, c));
  }
  for (auto& p : begmp) sort((p.second).begin(), (p.second).end());
  for (auto& p : endmp) sort((p.second).begin(), (p.second).end());
  long long ans = 1e15;
  for (int p1 = 1; p1 <= x; ++p1) {
    int p2 = x - p1;
    if (!endmp.count(p1) || !begmp.count(p2)) continue;
    const auto& v1 = endmp[p1];
    const auto& v2 = begmp[p2];
    int j = (int)((v2).size()) - 1;
    int minc = 0x3f3f3f3f;
    for (int i = (int)((v1).size()) - 1; i >= 0; --i) {
      int val = v1[i].first;
      int c = v1[i].second;
      while (j >= 0 && v2[j].first > val) {
        minc = min(minc, v2[j--].second);
      }
      if (minc != 0x3f3f3f3f) ans = min(ans, minc * 1LL + c);
    }
  }
  printf("%lld\n", (ans == (1e15) ? -1 : ans));
  return 0;
}
