#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
  cin >> N;
  vector<pair<int, int> > V(N);
  for (auto &v : V) cin >> v.first >> v.second;
  sort(V.begin(), V.end());
  int res = 0;
  priority_queue<int, vector<int>, greater<int> > Q;
  for (auto &v : V) {
    if (v.first - 2 <= (int)Q.size()) Q.push(v.second);
    while (!Q.empty() && Q.top() <= (int)Q.size()) {
      Q.pop();
    }
    res = max(res, (int)Q.size());
  }
  cout << res << endl;
}
