#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int N,table[100002]={};
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    int a,b;
    cin >> a >> b;
    for(int i = a ; i <= b ; i++ ) table[i]++;
  }
  int res = 0;
  for(int i = 0 ; i <= N + 1 ; i++ ){
    if( ++table[i] >= i) res = i - 1;
  }
  cout << res << endl;
}