#include <bits/stdc++.h>
using namespace std;
const int N = 201000, M = 3010100, inf = 0x7fffffff;
const long long llinf = 0x7fffffff7fffffffll;
struct Node {
  long long first, second, cost;
  bool operator<(const Node &tmp) const {
    if (first != tmp.first)
      return first < tmp.first;
    else
      return second < tmp.second;
  };
  long long len() { return second - first + 1; }
  Node(long long first, long long second) : first(first), second(second){};
  Node(){};
} node[N];
long long s[N];
int main(int argc, const char *argv[]) {
  int n, x;
  cin >> n >> x;
  for (int i = 0; i < n; ++i) {
    scanf("%lld%lld%lld", &node[i].first, &node[i].second, &node[i].cost);
  }
  sort(node, node + n);
  priority_queue<Node> queue;
  long long ans = llinf;
  for (int i = 0; i < n; ++i) {
    while (!queue.empty()) {
      long long topRight = -queue.top().first;
      if (topRight < node[i].first) {
        long long index = queue.top().second;
        long long len = node[index].len();
        if (!s[len]) {
          s[len] = node[index].cost;
        } else {
          s[len] = min(s[len], node[index].cost);
        }
        queue.pop();
      } else {
        break;
      }
    }
    if (node[i].len() < x && s[x - node[i].len()] > 0) {
      ans = min(ans, node[i].cost + s[x - node[i].len()]);
    }
    queue.push(Node(-node[i].second, i));
  }
  if (ans == llinf) {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
