#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  cin >> n;
  vector<vector<int> > ab(n + 2, vector<int>(0));
  vector<int> away(n + 2, 0);
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (a < n + 2) ab[a].push_back(b);
  }
  sort(ab.begin(), ab.end());
  int count = 1;
  int m = 1;
  for (int j = 1; j < n + 2; j++) {
    if (ab[j].size() == 0) continue;
    if (count + ab[j].size() < j) {
      count = count + ab[j].size();
      for (int k = 1; k <= ab[j].size(); k++) {
        away[(int)ab[j][k - 1] + 1]++;
      }
      continue;
    }
    for (int k = 1; k <= ab[j].size(); k++) {
      count++;
      count -= away[count];
      m = max(m, count);
      away[(int)ab[j][k - 1] + 1]++;
    }
  }
  cout << m - 1 << endl;
  return 0;
}
