#include <bits/stdc++.h>
using namespace std;
struct Section {
  int l, r;
  bool operator<(const Section& rhs) const {
    return r != rhs.r ? r > rhs.r : l < rhs.l;
  }
} sec[200010];
priority_queue<int, vector<int>, greater<int> > pq;
int main() {
  int N, M, l, r;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%d%d", &l, &r);
    sec[i] = (Section){l, r};
  }
  sort(sec, sec + N);
  int head = 1, rear = M, ans = 0;
  for (int i = 0; i < N; i++) {
    if (head > rear) ans++;
    l = sec[i].l, r = sec[i].r;
    bool ok = false;
    if (rear < r) {
      if (!pq.empty() && pq.top() < l && pq.top() >= head) {
        head++;
        pq.pop();
        if (l > 0) pq.push(l);
        ok = true;
      }
    } else {
      rear--;
      if (l > 0) pq.push(l);
      ok = true;
    }
    if (!ok && l >= head) {
      head++;
      ok = true;
    }
    if (!ok) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
