#include <bits/stdc++.h>
using namespace std;
struct segm {
  int l, r;
  int num;
  segm(int _l = 0, int _r = 0) : l(_l), r(_r) {}
  segm(int _l, int _r, int _num) : l(_l), r(_r), num(_num) {}
  inline bool operator<(const segm &s) const { return l < s.l; }
  inline int length() const { return r - l; }
  inline int operator||(const segm &s) const {
    return max(0, min(r, s.r) - max(l, s.l));
  }
};
struct event {
  int y;
  segm s;
  bool read() {
    if (scanf("%d%d%d", &y, &s.l, &s.r) < 3) return 0;
    return 1;
  }
  inline bool operator<(const event &e) const { return y > e.y; }
};
const int maxn = (int)1e5 + 2;
event evs[maxn];
set<segm> s;
int d[maxn];
int main() {
  int n, t;
  while (scanf("%d%d", &n, &t) >= 1) {
    evs[0].s = segm(-(int)1e9, (int)1e9), evs[0].y = 0;
    evs[1].s = segm(-(int)1e9, (int)1e9), evs[1].y = t;
    for (int i = 0; i < n; i++) evs[i + 2].read();
    n += 2;
    sort(evs, evs + n);
    for (int i = 0; i < n; i++) evs[i].s.num = i;
    d[0] = (int)2e9;
    s.clear();
    s.insert(evs[0].s);
    for (int i = 1; i < n; i++) {
      segm now = evs[i].s;
      bool first = 1;
      d[i] = 0;
      while (1) {
        set<segm>::iterator iter = s.lower_bound(now);
        segm cur;
        if (first) {
          first = 0;
          if (iter == s.begin()) continue;
          iter--;
          cur = *iter;
          if (!(cur || now)) continue;
        } else {
          if (iter == s.end()) break;
          cur = *iter;
          if (!(cur || now)) break;
        }
        s.erase(iter);
        if ((cur || now) == (evs[cur.num].s || now))
          d[i] = max(d[i], min(d[cur.num], (cur || now)));
        if ((cur || now) < cur.length()) {
          if (cur.l < now.l) s.insert(segm(cur.l, now.l, cur.num));
          if (cur.r > now.r) s.insert(segm(now.r, cur.r, cur.num));
        }
      }
      s.insert(now);
    }
    printf("%d\n", d[n - 1]);
  }
  return 0;
}
