#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if ((a == 0) || (b == 0)) return a + b;
  return gcd(b, a % b);
}
long long pow_mod(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return (res % 1000000007);
}
long long pow_2(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a);
    a = (a * a);
    b >>= 1;
  }
  return res;
}
bool isPrime(long long a) {
  for (long long i = 3; (i * i) <= a; i += 2) {
    if ((a % i) == 0) return false;
  }
  if ((a != 2) && ((a % 2) == 0)) return false;
  if (a == 1) return false;
  return true;
}
string con_ll_to_str(long long a) {
  stringstream mystr;
  mystr << a;
  return mystr.str();
}
long long con_str_to_ll(string st) {
  long long numb = 0;
  long long len = st.size(), i, j = 0;
  for (i = len - 1; i >= 0; i--) {
    numb += (pow_2(10, j) * (st[i] - '0'));
    j++;
  }
  return numb;
}
long long baseno_to_decimal(string st, long long basee) {
  long long i = 0, j, anss = 0;
  for (j = (int)st.length() - 1; j >= 0; j--) {
    anss += (st[j] - '0') * pow_2(basee, i);
    i++;
  }
  return anss;
}
string decimal_to_string(long long num, long long basee) {
  long long i = 0, j, opop;
  string anss = "";
  vector<string> stri;
  stri.push_back("0");
  stri.push_back("1");
  stri.push_back("2");
  stri.push_back("3");
  stri.push_back("4");
  stri.push_back("5");
  stri.push_back("6");
  stri.push_back("7");
  stri.push_back("8");
  stri.push_back("9");
  stri.push_back("A");
  stri.push_back("B");
  stri.push_back("C");
  stri.push_back("D");
  stri.push_back("E");
  stri.push_back("F");
  if (num == 0) {
    return "0";
  }
  while (num) {
    opop = num % basee;
    anss += stri[opop];
    num /= basee;
  }
  reverse(anss.begin(), anss.end());
  return anss;
}
const int dx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1};
long long arr[200010];
vector<pair<pair<long long, long long>, long long> > vc;
vector<pair<pair<long long, long long>, pair<long long, long long> > >
    vc2[200010];
vector<pair<long long, long long> > vc4[200010];
bool comp(pair<pair<long long, long long>, pair<long long, long long> > pa1,
          pair<pair<long long, long long>, pair<long long, long long> > pa2) {
  if (pa1.first.first == pa2.first.first) {
    return pa1.first.second < pa2.first.second;
  }
  return pa1.first.first < pa2.first.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long T, N, i, j, X, L, R, M, ans = 92203685477580799, op;
  string st;
  cin >> N >> X;
  for (i = 1; i <= N; i++) {
    cin >> L >> R >> M;
    vc.push_back(make_pair(make_pair(L, R), M));
  }
  for (i = 0; i <= N - 1; i++) {
    L = vc[i].first.first;
    R = vc[i].first.second;
    M = vc[i].second;
    vc2[R - L + 1].push_back(make_pair(make_pair(L, R), make_pair(M, M)));
  }
  for (i = 0; i <= 200000; i++) {
    sort(vc2[i].begin(), vc2[i].end(), comp);
  }
  for (i = 0; i <= 200000; i++) {
    for (j = (int)vc2[i].size() - 2; j >= 0; j--) {
      vc2[i][j].second.second =
          ((vc2[i][j].second.second) < (vc2[i][j + 1].second.second)
               ? (vc2[i][j].second.second)
               : (vc2[i][j + 1].second.second));
    }
    for (j = 0; j <= (int)vc2[i].size() - 1; j++) {
      vc4[i].push_back(vc2[i][j].first);
    }
  }
  for (i = 0; i <= N - 1; i++) {
    L = vc[i].first.first;
    R = vc[i].first.second;
    M = vc[i].second;
    op = X - (R - L + 1);
    if (op > 0) {
      if (vc2[op].size()) {
        long long itr = lower_bound(vc4[op].begin(), vc4[op].end(),
                                    make_pair(R + 1, R + 1)) -
                        vc4[op].begin();
        if (itr < vc4[op].size()) {
          ans = ((ans) < (M + vc2[op][itr].second.second)
                     ? (ans)
                     : (M + vc2[op][itr].second.second));
        }
      }
    }
  }
  if (ans == 92203685477580799) {
    cout << "-1";
    return 0;
  }
  cout << ans;
  return 0;
}
