#include <bits/stdc++.h>
using namespace std;
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>, less<int> > pq;
  priority_queue<int, vector<int>, less<int> > pq2;
  for (int i = 0; i < n; i++) {
    pq.push(p[i].second);
    while (!pq.empty() && pq.top() > r) {
      pq2.push(pq.top());
      pq.pop();
    }
    if (pq.size() + pq2.size() > p[i].first) {
      if (pq.empty()) {
        ans++;
        pq2.pop();
      } else {
        int a = pq.top();
        pq.pop();
        if (a > r) {
          if (!pq2.empty()) {
            pq2.pop();
            pq.push(a);
          }
          ans++;
        } else
          r--;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
