#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin>>n;
  vector<int> v(100005,0);
  for(int i=0;i<n;++i){
    int a,b;
    cin>>a>>b;
    ++v[a];
    --v[b+1];
  }
  int mx=0;
  for(int i=0;i<n+2;++i){
    v[i+1]+=v[i];
    if(v[i+1]>=i)mx=i;
  }
  cout<<mx<<endl;
  return 0;
}