#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  scanf("%lld", &n);
  ;
  vector<long long> ans(100003, 0);
  ans[0]++;
  for (long long i = 0; i < n; i++) {
    long long a;
    scanf("%lld", &a);
    ;
    long long b;
    scanf("%lld", &b);
    ;
    ans[a]++;
    ans[b + 1]--;
  }
  long long ret = 0;
  for (long long i = 1; i < n + 1; i++) {
    ans[i] += ans[i - 1];
    if (ans[i] >= i) {
      ret = i;
    }
  }
  cout << ret - 1 << endl;
  return 0;
}
