#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  map<int, int> imos;
  for (int i = (int)(0); i < (int)(n); ++i) {
    int a, b;
    cin >> a >> b;
    imos[a] += 1;
    imos[b] -= 1;
  }
  int ans = 0;
  int c = 0;
  for (int i = (int)(0); i < (int)(n + 1); ++i) {
    c += imos[i];
    if (c + 1 >= i) ans = max(ans, c);
  }
  cout << ans << endl;
  return 0;
}
