#include <bits/stdc++.h>
using namespace std;
int n, m, w[301000], cnt, s, M;
vector<int> E[201000];
priority_queue<int> PQ;
int main() {
  int i, b, e, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d%d", &b, &e);
    E[b].push_back(e);
  }
  for (i = 0; i <= m; i++) {
    for (j = 0; j < E[i].size(); j++) {
      PQ.push(-E[i][j]);
    }
    while (PQ.size() > i) {
      w[-PQ.top()]++;
      PQ.pop();
    }
  }
  int s = 0, r = PQ.size(), sz = PQ.size();
  for (i = m; i > sz; i--) {
    s++;
    r += min(s, w[i]);
    s -= min(s, w[i]);
  }
  printf("%d\n", n - r);
}
