#include <bits/stdc++.h>
using namespace std;
struct panel {
  int l, r, h;
  bool operator<(const panel &a) const { return h < a.h; }
} L[100009];
int n, m, f[100009], stk[100009], top;
int cross(int a, int b) { return min(L[a].r, L[b].r) - max(L[a].l, L[b].l); }
bool bad(int a, int b, int c) {
  return L[a].h > L[b].h && L[b].h > L[c].h && cross(a, b) && cross(a, c) &&
         cross(b, c);
}
int main() {
  cin >> n >> m;
  for (int i = 2; i <= n + 1; i++) scanf("%d%d%d", &L[i].h, &L[i].l, &L[i].r);
  L[0].l = -1000000000, L[0].r = 1000000000, L[0].h = 0;
  L[1].l = -1000000000, L[1].r = 1000000000, L[1].h = m;
  sort(L, L + n + 2);
  set<pair<int, int> > s;
  set<pair<int, int> >::iterator its, ite;
  s.insert(pair<int, int>(-1000000000, 0));
  s.insert(pair<int, int>(1000000000, 0));
  f[0] = 2 * 1000000000;
  for (int i = 1; i <= n + 1; i++) {
    int l = L[i].l, r = L[i].r, h = L[i].h;
    its = s.upper_bound(pair<int, int>(l, 1000000000));
    ite = --its;
    top = 0;
    while (ite->first < r) stk[top++] = ite->second, ite++;
    if (its->first != l) its++;
    s.erase(its, ite);
    s.insert(pair<int, int>(l, i));
    if (ite->first != r) s.insert(pair<int, int>(r, stk[top - 1]));
    for (int j = 0; j < top; j++) {
      if (j && bad(i, stk[j - 1], stk[j])) continue;
      if (j < top - 1 && bad(i, stk[j + 1], stk[j])) continue;
      f[i] = max(f[i], min(f[stk[j]], cross(i, stk[j])));
    }
  }
  cout << f[n + 1] << endl;
}
