#include <bits/stdc++.h>
using namespace std;
int x[100100], y[100100], z[100100], best[100100];
pair<int, int> p[2 * 100100];
bool cmp(pair<int, int> u, pair<int, int> v) { return z[u.first] > z[v.first]; }
int main() {
  int N, T, n, i, j, u, v;
  set<pair<int, int> >::iterator it, jt;
  scanf("%d%d", &N, &T);
  for (n = 0, i = 1; i <= N; i++) {
    scanf("%d%d%d", z + i, x + i, y + i);
    p[n++] = pair<int, int>(x[i], i);
    p[n++] = pair<int, int>(y[i], -i);
  }
  z[0] = T;
  z[N + 1] = 0;
  x[0] = x[N + 1] = -2000100000 / 2;
  y[0] = y[N + 1] = 2000100000 / 2;
  sort(p, p + n);
  set<pair<int, int> > Edge, Act;
  Edge.clear();
  Edge.insert(pair<int, int>(0, N + 1));
  Act.clear();
  Act.insert(pair<int, int>(T, 0));
  Act.insert(pair<int, int>(0, N + 1));
  for (i = 0; i < n; i = j) {
    for (j = i; j < n; j++) {
      if (p[j].first != p[i].first) break;
      if (p[j].second >= 0) break;
      Act.erase(pair<int, int>(z[-p[j].second], -p[j].second));
    }
    for (; j < n; j++) {
      if (p[j].first != p[i].first) break;
      if (p[j].second > 0) {
        it = Act.lower_bound(pair<int, int>(z[p[j].second], p[j].second));
        jt = it;
        jt--;
        u = it->second;
        v = jt->second;
        Edge.erase(pair<int, int>(u, v));
        Edge.insert(pair<int, int>(u, p[j].second));
        Edge.insert(pair<int, int>(p[j].second, v));
        Act.insert(pair<int, int>(z[p[j].second], p[j].second));
      }
    }
  }
  n = 0;
  for (it = Edge.begin(); it != Edge.end(); it++) {
    p[n++] = *it;
  }
  sort(p, p + n, cmp);
  for (i = 1; i <= N + 1; i++) best[i] = 0;
  best[0] = 2000100000;
  for (i = 0; i < n; i++) {
    u = p[i].first;
    v = p[i].second;
    best[v] = max(best[v], min(best[u], min(y[u], y[v]) - max(x[u], x[v])));
  }
  printf("%d\n", best[N + 1]);
  return 0;
}
