#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
int main(void)
{
  int n;
  cin >> n;
  vector<int> f(131072,0);
  REP(i,n){
    int l,r;
    cin >> l >> r;
    ++f[l];
    --f[r+1];
  }
  ++f[0];
  REP(i,131000) f[i+1]+=f[i];
  int answer=0;
  REP(i,131000) if(f[i]>=i) answer=i-1;
  cout << answer << endl;
  return 0;
}