#include<bits/stdc++.h>
using namespace std;

#define AA 100001
 
int main(){
  int N, a, b, temp[AA+100] = {}, ma = 0;

  cin>>N;

  for(int i = 0; i < N; i++){
    cin>>a>>b;
    temp[a]++;
    temp[b+1]--;
  }

  temp[0] = 1;

  for(int i = 1; i <= AA; i++){
    temp[i]+= temp[i-1];
    if(temp[i] >= i){
      ma = i;
    }
    // cout<<temp[i]<<" ";
  }

  cout<<ma-1<<endl;
  
  return 0;
}

