#include <bits/stdc++.h>
using namespace std;
struct ww {
  int l, r, h;
  inline bool operator<(const ww &A) const {
    return l < A.l || l == A.l && r < A.r;
  }
} a[200010];
int i, j, k, n, m;
int f[200010];
set<ww> Set;
inline bool cc1(const ww &a, const ww &b) { return a.h < b.h; }
inline int get(int x, int y) {
  return min(a[x].r, a[y].r) - max(a[x].l, a[y].l) + 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d%d%d", &a[i].h, &a[i].l, &a[i].r), a[i].r--;
  a[++n] = (ww){-1000000000, 1000000000 - 1, m};
  a[0] = (ww){-1000000000, 1000000000 - 1, 0};
  sort(a + 1, a + n + 1, cc1);
  Set.insert((ww){-1000000000, 0});
  Set.insert((ww){1000000000, 0});
  f[0] = 2 * 1000000000;
  for (i = 1; i <= n; i++) {
    ww B = a[i];
    set<ww>::iterator A = Set.lower_bound((ww){B.l, i});
    A--;
    for (;;) {
      if (A->l > B.r) break;
      set<ww>::iterator C = A;
      if (C != Set.begin()) C--;
      set<ww>::iterator D = A;
      D++;
      int Fir = C->r, Mid = A->r, Las = D->r;
      if ((a[Mid].h >= a[Fir].h || a[Fir].r < B.l || a[Fir].r < a[Mid].l) &&
          (a[Mid].h >= a[Las].h || a[Las].l > B.r || a[Mid].r < a[Las].l))
        f[i] =
            max(f[i], min(f[Mid], min(B.r, a[Mid].r) - max(B.l, a[Mid].l) + 1));
      A++;
    }
    A--;
    int X = A->r;
    A++;
    Set.erase(Set.lower_bound((ww){B.l, -1}), A);
    if (A->l != B.r + 1) Set.insert((ww){B.r + 1, X});
    Set.insert((ww){B.l, i});
  }
  printf("%d\n", f[n]);
  return 0;
}
