#include <bits/stdc++.h>
using namespace std;
array<int, 100002> box;
int n;
int np;
int min_;
int max_;
int solve() {
  cin >> n;
  np = n + 1;
  for (int i = 0; i < n; i++) {
    cin >> min_ >> max_;
    if (min_ > np) {
      continue;
    }
    box[min_ - 1]--;
    max_ = min(max_, np);
    box[max_]++;
  }
  box[np + 2] = 0;
  for (int i = np + 1; i >= 0; i--) {
    box[i] += box[i + 1];
    std::cout << "debug " << i << " " << box[i] << std::endl;
    if (i - 1 <= box[i]) {
      return i - 1;
    }
  }
  return 0;
}
int main() {
  cout << solve() << endl;
  return 0;
}
