#include <bits/stdc++.h>

using namespace std;

int main(){
  int N; cin >> N;
  const int MAX = 1e5+10;
  vector<int> cnt(MAX);
  for(int i=0;i<N;++i){
	int b, e; cin >> b >> e;
	++e;
	cnt[b]++;
	cnt[e]--;
  }

  vector<int> acc(MAX);
  for(int i=0,s=0;i<MAX;++i)
	acc[i] = (s += cnt[i]);

  int ans = 0;
  for(int i=0;i<MAX;++i)
	if(acc[i] >= i-1)
	  ans = i-1;
  
  cout << ans << endl;
  
  return 0;
}