#include<iostream>
#include<algorithm>
#include<cassert>
using namespace std;
int main(){
  int n,st,ed,ans,lim;
  int info[100100];
  while(cin >> n){
    ans = lim = 0;
    for(int i=0;i<100100;i++)info[i] = 0;
    for(int i=0;i<n;i++){
      cin >> st >> ed;
      lim = max(lim,ed);
      for(int i=st;i<=ed;i++)info[i]++;
    }
    for(int i=1;i<=lim;i++){
      if(info[i]+1>=i)ans = i;
    }
    cout << ans-1 << endl;
  }
  return 0;
}