#include <bits/stdc++.h>
using namespace std;
int a[100005] = {};
int main(void) {
  int max;
  cin >> max;
  a[0]++;
  for (int i = 0; i < max; ++i) {
    int c, b;
    cin >> c >> b;
    a[c - 1]++;
    a[b]--;
  }
  int sum = 0;
  int maxn = 1;
  for (int i = 0; i <= max; ++i) {
    sum += a[i];
    if (i <= sum) {
      maxn = i;
    }
  }
  cout << maxn << endl;
  return 0;
}
