#include <bits/stdc++.h>
using namespace std;

#define PI 4*atan(1)
#define INF 1e8

typedef long long ll;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main(){
  int N;
  cin >> N;
  vector<int> c(100000 + 2, 0);
  for(int i = 0; i < N; i++){
    int a, b;
    cin >> a >> b;
    c[a - 1]++;
    c[b]--;
  }
  int sum = 0, ans = 0;
  for(int i = 1; i <= N; i++){
    sum += c[i];
    if(i <= sum)ans = i;
  }
  cout << ans << endl;
}