#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());
  priority_queue<int, vector<int>, greater<int>> Q;
  vector<int> R;
  for (int i = 0; i < N; i++) {
    Q.push(P[i].second);
    if (Q.size() > P[i].first) {
      R.push_back(Q.top());
      Q.pop();
    }
  }
  sort(R.rbegin(), R.rend());
  int ans = 0;
  int cnt = 0;
  for (int i = 0; i < R.size(); i++) {
    int t = M + 1 - R[i];
    if (cnt >= t) {
      ans++;
    } else {
      cnt++;
    }
  }
  cout << ans << endl;
  return 0;
}
