#include <bits/stdc++.h>
using namespace std;
int n;
int p[111111];
int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    p[a - 1]++;
    p[b]--;
  }
  int best = 0;
  for (int i = 1; i <= 100001; i++) {
    p[i] += p[i - 1];
    if (i < p[i]) {
      best = i;
    }
  }
  cout << best << endl;
}
