#include <bits/stdc++.h>
using namespace std;
int n;
int a[100000], b[100000];
int imos[100100];
int solve() {
  int cnt = 1;
  int ret = 0;
  for (int i = 1; i <= 100000; i++) {
    cnt += imos[i];
    if (cnt >= i) {
      ret = i - 1;
    }
  }
  return ret;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (cin >> n) {
    memset(imos, 0, sizeof imos);
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
      imos[a[i]]++;
      imos[b[i] + 1]--;
    }
    cout << solve() << endl;
  }
}
