#include <bits/stdc++.h>
template <typename T>
std::vector<std::vector<T>> read_input() {
  std::string input_str;
  std::getline(std::cin, input_str);
  int arr_size = std::stoi(input_str);
  std::vector<std::vector<T>> input_vec(arr_size, std::vector<int>(2, 0));
  for (size_t i = 0; i < arr_size; i++) {
    std::getline(std::cin, input_str);
    std::istringstream iss(input_str);
    T begin, end;
    iss >> begin >> end;
    begin -= 1;
    end -= 1;
    input_vec.at(i).at(0) = begin;
    input_vec.at(i).at(1) = end;
  }
  return input_vec;
}
bool search(std::vector<std::vector<int>> input_vec, int ans) {
  if (ans == 0) {
    return true;
  }
  int count = 0;
  for (int i = 0; i < input_vec.size(); i++) {
    std::vector<int> person = input_vec.at(i);
    if (person.at(0) <= ans && ans <= person.at(1)) {
      count++;
    }
    if (count == ans) {
      return true;
    }
  }
  return false;
}
int main(int argc, char const *argv[]) {
  std::vector<std::vector<int>> input_vec = read_input<int>();
  int ans;
  for (int num = 0; num <= input_vec.size(); num++) {
    if (search(input_vec, num)) {
      ans = num;
    } else {
      break;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
