#include<cstdio>

using namespace std;

const int MAX = 100005;
int dp[MAX];

int main(){

  int n;
  scanf("%d",&n);

  while(n--){
    int a,b;
    scanf("%d %d",&a,&b);
    for(int i = a; i <= b; i++) dp[i]++;
  }

  for(int i = MAX-1; i>0; i--)
    if(dp[i] >= i-1){
      printf("%d\n",i-1);
      break;
    }
  return 0;
}