#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10, inf = (int)1e9;
struct segment {
  int h, l, r;
} seg[N];
bool operator<(const segment &a, const segment &b) { return a.h > b.h; }
struct zed {
  int l, r, pd, num;
  zed(int _l, int _r, int _pd, int _num) : l(_l), r(_r), pd(_pd), num(_num){};
};
bool operator<(const zed &a, const zed &b) { return a.r < b.r; }
int dp, ans, n, t;
multiset<zed> Q;
multiset<zed>::iterator itr;
int main() {
  scanf("%d%d", &n, &t);
  for (int i = 0; i < n; ++i)
    scanf("%d%d%d", &seg[i].h, &seg[i].l, &seg[i].r), seg[i].l++;
  sort(seg, seg + n);
  seg[n].l = -inf;
  seg[n].r = inf;
  Q.insert(zed(-inf, inf, 0, inf * 2 + 1));
  for (int i = 0, flow; i <= n; ++i, dp = 0) {
    zed t = zed(seg[i].r, seg[i].l, 0, 0);
    itr = Q.lower_bound(t);
    swap(t.l, t.r);
    for (; itr != Q.end() && itr->l <= t.r; Q.erase(itr++)) {
      flow = min(min(itr->r, t.r) - max(itr->l, t.l) + 1, itr->num);
      if (((itr->r < t.r) && (itr->pd & 1)) ||
          ((t.l < itr->l) && (itr->pd & 2))) {
      } else
        dp = max(dp, flow);
      if (itr->r > t.r) Q.insert(zed(t.r + 1, itr->r, itr->pd | 2, itr->num));
      if (itr->l < t.l) Q.insert(zed(itr->l, t.l - 1, itr->pd | 1, itr->num));
    }
    if (i == n) printf("%d\n", dp);
    t.num = dp;
    Q.insert(t);
  }
  return 0;
}
