#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, h, num, flag;
};
int n, t, tot, f[100010], maxx;
typedef int arr[500010];
set<int> G[100010];
arr l, r, h, d;
priority_queue<node> pq;
set<pair<int, int> > s;
queue<int> Q;
bool operator<(const node& a, const node& b) {
  if (a.l != b.l) return a.l > b.l;
  return a.flag > b.flag;
}
inline int flow(int a, int b) {
  if (a > n) return r[b] - l[b];
  if (b > n) return r[a] - l[a];
  return min(r[a], r[b]) - max(l[a], l[b]);
}
inline void init() {
  scanf("%d%d", &n, &t);
  for (int i = 1; i <= n; i++) {
    int a, b, c;
    scanf("%d%d%d", &h[i], &l[i], &r[i]);
    pq.push((node){l[i], h[i], i, 1});
    pq.push((node){r[i], h[i], i, -1});
  }
  s.insert(make_pair(t, n + 1));
  s.insert(make_pair(0, n + 2));
}
inline void make(node x) {
  set<pair<int, int> >::iterator it = s.insert(make_pair(x.h, x.num)).first,
                                 pre = it, succ = it;
  pre--;
  G[x.num].insert(pre->second);
  succ++;
  G[succ->second].insert(x.num);
  G[succ->second].erase(pre->second);
}
int main() {
  init();
  while (!pq.empty()) {
    int tmp = pq.top().l;
    for (; !pq.empty() && pq.top().l == tmp; pq.pop())
      if (pq.top().flag == 1)
        make(pq.top());
      else
        s.erase(make_pair(pq.top().h, pq.top().num));
  }
  Q.push(n + 1);
  f[n + 1] = 2147483647;
  for (int x = 1; x <= n + 2; x++)
    for (set<int>::iterator i = G[x].begin(); i != G[x].end(); i++) d[*i]++;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (set<int>::iterator i = G[x].begin(); i != G[x].end(); i++) {
      f[*i] = max(f[*i], min(f[x], flow(x, *i)));
      --d[*i];
      if (d[*i] == 0) Q.push(*i);
    }
  }
  return printf("%d\n", f[n + 2]), 0;
}
