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