#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  map<long long, int> mp;
  for (int i = 0; i < n; ++i) {
    long long a, b;
    cin >> a >> b;
    mp[a]++;
    mp[b]--;
  }
  int num = 1;
  int ans = 1;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    num += it->second;
    if (num >= it->first) ans = max(ans, num);
  }
  cout << ans - 1 << endl;
  return 0;
}
