#include <bits/stdc++.h>
using namespace std;
int N, M, L[200009], R[200009];
vector<int> vec[200009];
priority_queue<int, vector<int>, greater<int>> Q;
int main() {
  cin >> N >> M;
  M++;
  for (int i = 1; i <= N; i++) {
    cin >> L[i] >> R[i];
    vec[L[i]].push_back(R[i]);
  }
  for (int i = M; i > N; i--) {
    for (int j : vec[i]) Q.push(M - j);
  }
  for (int i = N; i >= 1; i--) {
    for (int j : vec[i]) Q.push(M - j);
    if (!Q.empty()) {
      Q.pop();
    }
  }
  for (int j : vec[0]) Q.push(M - j);
  vector<int> v;
  while (!Q.empty()) {
    v.push_back(Q.top());
    Q.pop();
  }
  int B = 1, cnt = v.size();
  for (int i = 0; i < v.size(); i++) {
    if (B <= v[i]) {
      B++;
      cnt--;
    }
  }
  cout << cnt << endl;
  return 0;
}
