#include <set>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int a[100000 + 3];
int b[100000 + 3];

int main(){
  int n = getInt();

  REP(i,n){
    int aa = getInt();
    int bb = getInt();

    a[aa]++; b[bb]++;
  }

  int ans = 0;
  int peo = 1;

  REP(i,100000 + 3){
    peo += a[i];
    if(i > 0) peo -= b[i - 1];

    if(peo >= i){
      ans = i - 1;
    }
  }

  printf("%d\n", ans);

  return 0;
}