#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(n);
  for (int i = 0; i < (n); i++) cin >> p[i].first >> p[i].second;
  sort((p).begin(), (p).end(),
       [](pair<int, int> &l, pair<int, int> &r) { return l.first > r.first; });
  int ls = 0;
  for (int i = 0; i < n;) {
    int li = p[i].first;
    if (li == 0) {
      break;
    }
    while (i < n) {
      if (p[i].first < li) break;
      i++;
    }
    ls++;
  }
  priority_queue<int> q;
  int i = 0;
  for (int li = ls; li >= 1; li--) {
    while (i < n) {
      if (p[i].first < li) break;
      q.push(p[i].second);
      i++;
    }
    q.pop();
  }
  for (; i < n; i++) {
    q.push(p[i].second);
  }
  priority_queue<int> r;
  while (!q.empty()) {
    r.push(-q.top());
    q.pop();
  }
  int rs = 0;
  for (int j = ls + 1; j <= m; j++) {
    if (r.empty()) break;
    if (j >= -r.top()) {
      rs++;
      r.pop();
    }
  }
  cout << n - ls - rs << endl;
  return 0;
}
