#include <bits/stdc++.h>
using namespace std;
long long x[100001];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for (long long i = 0; i < 100001; i++) x[i] = 0;
  long long N;
  cin >> N;
  N++;
  for (long long i = 0; i < N - 1; i++) {
    long long l, r;
    cin >> l >> r;
    if (l > N) continue;
    r = min(r, N);
    for (long long j = l; j <= r; j++) {
      x[j]++;
    }
  }
  for (long long i = 100001 - 1; i >= 2; i--) {
    if (x[i] + 1 >= i) {
      cout << i - 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}
