#include <iostream>
using namespace std;

int main(){
  int n;

  while(cin>>n){
    int dec[100002];
    int inc[100002];

    for(int i=0;i<100002;i++){
      dec[i] = 0;
      inc[i] = 0;
    }

    for(int i=0;i<n;i++){
      int a,b;
      cin>>a>>b;
      inc[a]++;
      dec[b]++;
    }

    int now = 0;
    int ans = 0;

    for(int i=0;i<100002;i++){
      now += inc[i];
      if(now + 1 >= i) ans = max(ans, i);
      now -= dec[i];
    }

    cout<<ans-1<<endl;
  }
}