#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int arr[100010] = {};
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    arr[a]++;
    arr[b + 1]--;
  }
  for (int i = 1; i < 100010; i++) {
    arr[i] += arr[i - 1];
  }
  for (int i = 100000; 1 <= i; i--) {
    if (arr[i] >= i - 1) {
      cout << i << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}
