#include <bits/stdc++.h>
using namespace std;
int f[200005];
int Find(int a) {
  if (f[a] == a) return a;
  return f[a] = Find(f[a]);
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  pair<int, int> p[200005];
  for (int i = 0; i < n; i++) scanf("%d %d", &p[i].first, &p[i].second);
  sort(p, p + n);
  int r = m, ans = 0;
  priority_queue<int, vector<int>, greater<int> > pq;
  for (int i = 0; i < 200005; i++) f[i] = i;
  for (int i = 0; i < n; i++) {
    pq.push(p[i].second);
    if (pq.size() > p[i].first) {
      int a = pq.top();
      pq.pop();
      int fa = Find(a);
      if (fa != m + 1) {
        f[fa] = fa + 1;
      } else {
        ans++;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
