#include <bits/stdc++.h>
const int N = 100000 + 9;
std::set<std::pair<int, int> > s;
std::pair<int, int> tmp;
int f[N];
struct info {
  int l, r, h;
  inline bool operator<(const info &o) const { return h > o.h; }
} se[N];
inline bool check(int l, int j, int i) {
  return l == -1 || se[l].h >= se[j].h || se[l].r <= se[i].l ||
         se[i].r <= se[l].l || se[l].r <= se[j].l || se[j].r <= se[l].l;
}
int n;
int main() {
  scanf("%d%d", &n, &se[1].h);
  se[1].l = -1000000000;
  se[1].r = -se[1].l;
  ++n;
  for (int i = 2; i <= n; ++i) scanf("%d%d%d", &se[i].h, &se[i].l, &se[i].r);
  se[++n].h = 0;
  se[n].l = se[1].l;
  se[n].r = se[1].r;
  std::sort(se + 1, se + 1 + n);
  s.insert(std::make_pair(-1000000000, 1));
  s.insert(std::make_pair(-2000000000, -1));
  s.insert(std::make_pair(2000000000, -1));
  f[1] = 2000000000;
  for (int i = 2; i <= n; ++i) {
    std::set<std::pair<int, int> >::iterator p = s.lower_bound(std::make_pair(
                                                 se[i].l + 1, 0)),
                                             l, j, k;
    --p;
    for (k = p, l = k++, j = l--; j != s.end() && j->first < se[i].r;
         l = j, j = k++)
      if (check(l->second, j->second, i) && check(k->second, j->second, i))
        f[i] = std::max(f[i], std::min(f[j->second],
                                       std::min(se[j->second].r, se[i].r) -
                                           std::max(se[j->second].l, se[i].l)));
    if (p->first < se[i].l) ++p;
    bool flg = false;
    if (j->first > se[i].r)
      tmp = std::make_pair(se[i].r, l->second), flg = true;
    s.erase(p, j);
    if (flg) s.insert(tmp);
    s.insert(std::make_pair(se[i].l, i));
  }
  printf("%d\n", f[n]);
}
