#include <iostream>
using namespace std;

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