#include <bits/stdc++.h>
using namespace std;
const int MAXN = 120101;
set<pair<int, int> > s;
set<pair<int, int> >::iterator st, it, pre, nex;
int h[MAXN], l[MAXN], r[MAXN], p1[MAXN], f[MAXN];
int n;
int p, q;
bool cmp(int a, int b) { return h[a] > h[b]; }
int main() {
  scanf("%d%d", &n, &h[0]);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &h[i], &l[i], &r[i]);
    p1[i] = i;
  }
  l[0] = -2e9;
  r[0] = 2e9;
  f[0] = 2e9;
  h[n + 1] = -1;
  l[n + 1] = -1e9;
  r[n + 1] = 1e9;
  p1[n + 1] = n + 1;
  sort(p1 + 1, p1 + n + 1, cmp);
  s.insert(make_pair(-1e9, 0));
  s.insert(make_pair(1e9, 0));
  for (int o = 1; o <= n + 1; ++o) {
    int i = p1[o], j;
    st = s.lower_bound(make_pair(l[i], i));
    for (it = st, it--; it->first < r[i]; ++it) {
      pre = it;
      if (pre != s.begin()) pre--;
      nex = it;
      nex++;
      j = it->second;
      p = pre->second;
      q = nex->second;
      if ((h[j] <= h[p] || l[j] >= r[p] || r[p] <= l[i]) &&
          (h[j] <= h[q] || l[q] >= r[j] || r[i] <= l[q]))
        f[i] = max(f[i], min(f[j], min(r[i], r[j]) - max(l[i], l[j])));
    }
    --it;
    j = it->second;
    s.erase(st, ++it);
    if (r[i] != it->first) s.insert(make_pair(r[i], j));
    s.insert(make_pair(l[i], i));
  }
  printf("%d\n", f[n + 1]);
  return 0;
}
