#include <iostream>
#include <algorithm>

int imos[100010];

using namespace std;


int main() {
  int n;
  cin >> n;
  
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    imos[a - 1]++;
    imos[b]--;
  }

  int ans = 0;
  int current = 0;
  for (int i = 1; i < 100010; i++) {
    current += imos[i];
    if (current >= i) {
      ans = i;
    }
  }

  cout << ans << endl;

  return 0;
}