#include <iostream>
#include <vector>

using namespace std;

int main(void){
  int n;
  cin>>n;
  int a,b;
  int dp[100010] = {0};
  for(int i = 0 ; i < n ; i ++){
    cin>>a>>b;
    dp[a]++;
    dp[b+1]--;
  }
  int ret = 0;
  for(int i = 0 ; i < 100009 ; i ++){
    dp[i+1] += dp[i];
    if(i-1<=dp[i])ret = max(ret,i-1);
  } 
  cout<<ret<<endl;
}