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