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