#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
struct data_t {
  int min;
  int max;
  bool operator<(const data_t& right) const {
    if (min == right.min) {
      return ((max < right.max) || (max == right.max));
    } else {
      return (min < right.min);
    }
  }
};
int main(void) {
  int N;
  cin >> N;
  std::vector<data_t> fri(N);
  for (int i = 0; i < N; i++) {
    cin >> fri[i].min >> fri[i].max;
  }
  std::sort(fri.begin(), fri.end());
  int ret = 0;
  int count;
  bool end = false;
  for (int f = 2; f < N + 2; f++) {
    count = 1;
    end = false;
    for (int i = 0; i < N && !(end); i++) {
      if (fri[i].min <= f && fri[i].max >= f) {
        count++;
      } else {
        end = true;
      }
    }
    if (count != 1 && count > ret) {
      if (count >= f) {
        ret = f - 1;
      }
    }
  }
  cout << ret << endl;
  return 0;
}
