#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
template <class V, int NV>
struct LazySegTree {
  vector<V> dat, lazy;
  LazySegTree() {
    dat.resize(NV * 2, def);
    lazy.resize(NV * 2, ldef);
  }
  void update(int a, int b, V v, int k, int l, int r) {
    push(k, l, r);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      setLazy(k, v);
      push(k, l, r);
    } else {
      update(a, b, v, k * 2 + 1, l, (l + r) / 2);
      update(a, b, v, k * 2 + 2, (l + r) / 2, r);
      dat[k] = comp(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  V get(int a, int b, int k, int l, int r) {
    push(k, l, r);
    if (r <= a || b <= l) return def;
    if (a <= l && r <= b) return dat[k];
    auto x = get(a, b, k * 2 + 1, l, (l + r) / 2);
    auto y = get(a, b, k * 2 + 2, (l + r) / 2, r);
    return comp(x, y);
  }
  void update(int a, int b, V v) { update(a, b, v, 0, 0, NV); }
  V get(int a, int b) { return get(a, b, 0, 0, NV); }
  const V def = 0, ldef = -1;
  V comp(V l, V r) { return max(l, r); }
  void setLazy(int i, V v) { lazy[i] += v; }
  void push(int k, int l, int r) {
    if (lazy[k] != ldef) {
      dat[k] += lazy[k];
      if (r - l > 1) {
        setLazy(k * 2 + 1, lazy[k]);
        setLazy(k * 2 + 2, lazy[k]);
      }
      lazy[k] = ldef;
    }
  }
};
int N, M, L[201010], R[201010];
int solveOM2N() {
  int ans = max(0, N - M);
  for (int LL = 0; LL < M + 2; LL++)
    for (int RR = LL + 1; RR < M + 2; RR++) {
      int chair = LL + M + 1 - RR;
      int human = 0;
      for (int i = 0; i < N; i++)
        if (L[i] <= LL && RR <= R[i]) human++;
      ans = max(ans, human - chair);
    }
  return ans;
}
pair<int, int> LR[201010];
LazySegTree<int, 1 << 18> st;
int solveONlogM() {
  for (int i = 0; i < N; i++) LR[i] = {L[i], R[i]};
  sort(LR, LR + N);
  for (int i = 1; i < M + 2; i++) st.update(i, i + 1, i);
  int ans = max(0, N - M);
  for (int i = 0; i < N; i++) {
    st.update(0, LR[i].second + 1, 1);
    ans = max(ans, st.get(0, M + 2) - (LR[i].first + M + 1));
  }
  return ans;
}
void _main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> L[i] >> R[i];
  cout << solveONlogM() << endl;
}
