#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int MAXN = 300007;
struct Board {
  int l, r, h, idx;
  Board(int l, int r, int h) : l(l), r(r), h(h) {}
  bool operator<(const Board &o) const { return h > o.h; }
};
vector<int> edge[MAXN];
long long dp[MAXN];
void connect(const vector<Board> &boards, bool reversed) {
  set<pair<int, int> > s;
  for (int i = 0; i < boards.size(); i++) {
    set<pair<int, int> >::iterator it =
        s.upper_bound(make_pair(boards[i].l, 1000000000));
    int last = -2000000000;
    while (it != s.end()) {
      const Board &next = boards[it->second];
      if (it->first <= boards[i].r) {
        if (next.l >= last) {
          if (reversed) {
            edge[boards[i].idx].push_back(next.idx);
          } else {
            edge[next.idx].push_back(boards[i].idx);
          }
        }
      } else {
        if (next.l >= last && next.l < boards[i].r) {
          if (reversed) {
            edge[boards[i].idx].push_back(next.idx);
          } else {
            edge[next.idx].push_back(boards[i].idx);
          }
        }
        break;
      }
      last = it->first;
      set<pair<int, int> >::iterator it1 = it;
      it1++;
      s.erase(it);
      it = it1;
    }
    s.insert(make_pair(boards[i].r, i));
  }
}
int main() {
  int n, t;
  cin >> n >> t;
  vector<Board> boards;
  for (int i = 0; i < n; i++) {
    int h, l, r;
    scanf("%d%d%d", &h, &l, &r);
    boards.push_back(Board(l, r, h));
  }
  boards.push_back(Board(-1000000000, 1000000000, t));
  boards.push_back(Board(-1000000000, 1000000000, 0));
  sort(boards.begin(), boards.end());
  for (int i = 0; i < boards.size(); i++) {
    boards[i].idx = i;
  }
  connect(boards, false);
  reverse(boards.begin(), boards.end());
  connect(boards, true);
  reverse(boards.begin(), boards.end());
  dp[0] = 2000000000;
  for (int i = 0; i < boards.size(); i++) {
    for (typeof(edge[i].begin()) it = edge[i].begin(); it != edge[i].end();
         it++) {
      int to = *it;
      long long maxl = max(boards[i].l, boards[to].l);
      long long minr = min(boards[i].r, boards[to].r);
      assert(maxl < minr);
      dp[to] = max(dp[to], min(dp[i], minr - maxl));
    }
  }
  cout << dp[boards.size() - 1] << endl;
  return 0;
}
