#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
struct LazySegmentTree {
 private:
  int n;
  vector<long long> node, lazy;

 public:
  LazySegmentTree() {
    int sz = 300010;
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, 0);
    for (int i = 0; i < sz; i++) node[i + n - 1] = -1e9;
    for (int i = n - 2; i >= 0; i--)
      node[i] = max(node[i * 2 + 1], node[i * 2 + 2]);
  }
  void eval(int k, int l, int r) {
    if (lazy[k] != 0) {
      node[k] += lazy[k];
      if (r - l > 1) {
        lazy[2 * k + 1] += lazy[k];
        lazy[2 * k + 2] += lazy[k];
      }
      lazy[k] = 0;
    }
  }
  void add(int a, int b, long long x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] += x;
      eval(k, l, r);
    } else {
      add(a, b, x, 2 * k + 1, l, (l + r) / 2);
      add(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = max(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  long long getmax(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (b <= l || r <= a) return -1e9;
    if (a <= l && r <= b) return node[k];
    long long vl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
    long long vr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};
long long N, M;
long long L[305000], R[305000];
vector<pair<long long, long long> > v;
long long ans = 0;
LazySegmentTree seg;
void print() {
  return;
  for (int i = 0; i <= M + 1; i++) {
    cerr << seg.getmax(i, i + 1) << " ";
  }
  cerr << endl;
}
int solve() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  v.clear();
  for (int i = 0; i < N; i++) {
    v.push_back({L[i], -R[i]});
  }
  seg = LazySegmentTree();
  print();
  seg.add(0, M + 2, 1e9);
  print();
  for (int i = M; i >= 0; i--) {
    seg.add(i, i + 1, -(M + 1 - i));
  }
  seg.add(0, 1, 1);
  print();
  sort(v.begin(), v.end());
  for (int i = 0; i < N; i++) {
    seg.add(0, -v[i].second + 1, 1);
    print();
    long long maxi = seg.getmax(v[i].first + 1, M + 2);
    long long now = -v[i].first + maxi;
    chmax(ans, now);
  }
  return 0;
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> L[i] >> R[i];
  }
  solve();
  cout << ans << endl;
}
