#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-10;
int cnt[100010];
int main() {
  int N, a, b;
  while (cin >> N) {
    int best = 0;
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < N; i++) {
      cin >> a >> b;
      cnt[a]++;
      cnt[++b]--;
    }
    int num = 1;
    for (int i = 0; i < 100001; i++) {
      num += cnt[i];
      if (num >= i) best = i;
    }
    cout << best - 1 << endl;
  }
  return 0;
}
