#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int inf = 0x3f3f3f3f;
int n, t;
pair<int, pair<int, int> > a[maxn];
set<pair<pair<int, int>, int> > now;
int d[maxn];
int main() {
  scanf("%d %d", &n, &t);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &a[i].first, &a[i].second.first, &a[i].second.second);
    if (a[i].first == t) {
      n--;
      i--;
    }
  }
  a[n++] = make_pair(0, make_pair(-inf, inf));
  a[n++] = make_pair(t, make_pair(-inf, inf));
  sort(a, a + n);
  d[0] = inf << 1;
  now.insert(make_pair(a[0].second, 0));
  for (int i = 1; i < n; i++) {
    set<pair<pair<int, int>, int> >::iterator iter = now.lower_bound(
        make_pair(make_pair(a[i].second.first, -inf - 1), -inf));
    if (iter != now.begin()) iter--;
    vector<pair<pair<int, int>, int> > del, add;
    for (; iter != now.end(); iter++) {
      if (iter->first.second <= a[i].second.first) continue;
      if (iter->first.first >= a[i].second.second) break;
      del.push_back(*iter);
      bool ok = true;
      if (iter->first.first > a[i].second.first &&
          iter->first.first != a[iter->second].second.first)
        ok = false;
      if (iter->first.second < a[i].second.second &&
          iter->first.second != a[iter->second].second.second)
        ok = false;
      if (ok) {
        int temp = min(a[iter->second].second.second, a[i].second.second);
        temp -= max(a[iter->second].second.first, a[i].second.first);
        d[i] = max(d[i], min(d[iter->second], temp));
      }
      if (iter->first.first < a[i].second.first)
        add.push_back(make_pair(make_pair(iter->first.first, a[i].second.first),
                                iter->second));
      if (iter->first.second > a[i].second.second)
        add.push_back(make_pair(
            make_pair(a[i].second.second, iter->first.second), iter->second));
    }
    for (int j = 0; j < del.size(); j++) now.erase(now.find(del[j]));
    for (int j = 0; j < add.size(); j++)
      if (add[j].first.first < add[j].first.second) now.insert(add[j]);
    now.insert(make_pair(a[i].second, i));
  }
  printf("%d\n", d[n - 1]);
  return 0;
}
