#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int *a, *b;
  int *data;
  cin >> n;
  a = new int[n];
  b = new int[n];
  data = new int[100010];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < 100010; i++) {
    data[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    data[a[i]]++;
    data[b[i] + 1]--;
  }
  int num = 0;
  for (int i = 0; i < 10; i++) {
  }
  for (int i = 0; i < 10; i++) {
    num += data[i];
    data[i] = num;
  }
  for (int i = n + 1; i > 0; i--) {
    if (data[i] + 1 >= i) {
      cout << i - 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}
