#include <bits/stdc++.h>
using namespace std;
const long long MAX = 100001;
long long n;
long long a[MAX], b[MAX];
signed main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  long long imos[MAX + 2];
  fill(imos, imos + MAX + 2, 0);
  imos[0]++;
  for (long long i = 0; i < n; i++) {
    imos[a[i]]++;
    imos[b[i] + 1]--;
  }
  for (long long i = 1; i < MAX + 2; i++) {
    imos[i] += imos[i - 1];
  }
  for (long long i = n; i >= 2; i--) {
    if (imos[i] >= i) {
      cout << i - 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}
