#include <bits/stdc++.h>
using namespace std;
int n, m;
int l[200005], r[200005];
int main(void) {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> l[i] >> r[i];
  int ans = 0, L = 0, R = m + 1;
  for (int i = 1; i <= n; i++) {
    L = max(L, l[i]), R = min(R, r[i]);
    int num = min(m, L + (m + 1 - R));
    ans = max(ans, i - num);
  }
  cout << ans << endl;
  return 0;
}
