#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
set<pair<int, int> > s, e;
long long dp[N];
int l[N], r[N];
struct Point {
  int x, h, k;
  bool f;
} p[2 * N];
struct temp {
  int h, k;
} q[N];
int m;
bool cmp1(const temp &a, const temp &b) { return a.h > b.h; }
bool cmp(const Point &a, const Point &b) {
  if (a.x != b.x) return a.x < b.x;
  if (a.f != b.f) return a.f;
  return a.k < b.k;
}
vector<int> tran[N];
int main() {
  set<pair<int, int> >::iterator it;
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 0; i < n; i++) {
    int h;
    scanf("%d%d%d", &h, &l[i + 1], &r[i + 1]);
    p[m].x = l[i + 1], p[m].h = h, p[m].k = i + 1, p[m++].f = false;
    p[m].x = r[i + 1], p[m].h = h, p[m].k = i + 1, p[m++].f = true;
    q[i].h = h, q[i].k = i + 1;
  }
  l[0] = -(1 << 30), r[0] = (1 << 30);
  l[n + 1] = -(1 << 30), r[n + 1] = (1 << 30);
  q[n].h = t, q[n].k = 0;
  q[n + 1].h = 0, q[n + 1].k = n + 1;
  sort(p, p + m, cmp);
  sort(q, q + n + 2, cmp1);
  s.insert(make_pair(t, 0));
  s.insert(make_pair(0, n + 1));
  for (int i = 0; i < m; i++) {
    if (p[i].f) {
      it = s.find(make_pair(p[i].h, p[i].k));
      if (it != s.end()) s.erase(it);
    } else {
      int a, b;
      it = s.lower_bound(make_pair(p[i].h, 0));
      a = it->second;
      --it;
      b = it->second;
      it = e.find(make_pair(a, b));
      if (it != e.end()) e.erase(it);
      e.insert(make_pair(a, p[i].k));
      e.insert(make_pair(p[i].k, b));
      s.insert(make_pair(p[i].h, p[i].k));
    }
  }
  for (it = e.begin(); it != e.end(); it++)
    tran[it->first].push_back(it->second);
  dp[0] = (1ll << 50);
  for (int i = 0; i < n + 2; i++) {
    int now = q[i].k;
    for (int j = 0; j < tran[now].size(); j++) {
      int tag = tran[now][j];
      dp[tag] = max(
          dp[tag], min(dp[now], min((long long)r[now], (long long)r[tag]) -
                                    max((long long)l[now], (long long)l[tag])));
    }
  }
  printf("%I64d\n", dp[n + 1]);
  return 0;
}
