#include <bits/stdc++.h>
using namespace std;
int tmp[200000 + 5];
struct Person {
  int l, r;
  friend bool operator<(Person p, Person q) {
    if (p.l == q.l) {
      return p.r < q.r;
    }
    return p.l < q.l;
  }
} a[200000 + 5];
priority_queue<int, vector<int>, greater<int> > q;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i].l, &a[i].r);
  }
  sort(a + 1, a + 1 + n);
  int h = 0, len = 0;
  for (int i = 1; i <= n; i++) {
    q.push(a[i].r);
    if (h <= a[i].l) {
      h++;
    } else {
      tmp[++len] = q.top();
      q.pop();
    }
  }
  sort(tmp + 1, tmp + 1 + len);
  int ans = 0, t = m;
  for (int i = len; i > 0; i--) {
    if (t >= tmp[i]) {
      t--;
    } else {
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
