#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int memo[200000] = {};
  for (int i = 0; i < (n); i++) {
    int a, b;
    cin >> a >> b;
    memo[a]++;
    memo[b]--;
  }
  int ans = 0;
  for (int i = 0; i < (190000); i++) {
    memo[i + 1] = memo[i + 1] + memo[i];
    if (memo[i + 1] + 1 >= i + 1) {
      int x = min(memo[i + 1], i + 1);
      ans = max(ans, x);
    }
  }
  cout << ans << endl;
}
