#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<pair<int, int> > P(N);
  for (auto &i : P) cin >> i.first >> i.second;
  int l = 0, r = 100002;
  while (r - l > 1) {
    int m = (r + l) / 2;
    int count = 0;
    for (int i = 0; i < N; i++) {
      if (P[i].first > m + 1 || P[i].second < m + 1) {
        count++;
      }
    }
    if (m <= N - count) {
      l = m;
    } else {
      r = m;
    }
  }
  cout << l << endl;
  return 0;
}
