#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::list;
using std::make_pair;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::priority_queue;
using std::queue;
using std::set;
using std::setprecision;
using std::stack;
using std::string;
using std::vector;
int n;
bool check(vector<vector<int> >& table, int number) {
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (table[i][0] <= number && table[i][1] >= number) {
      count++;
    }
  }
  if (count >= number - 1) {
    return true;
  } else {
    return false;
  }
}
int main(void) {
  cin >> n;
  vector<vector<int> > table(n, vector<int>(2));
  for (int i = 0; i < n; i++) {
    cin >> table[i][0] >> table[i][1];
  }
  int left = 1;
  int right = n + 1;
  while (left < right) {
    int middle = (left + right) / 2;
    if (check(table, middle) == false) {
      right = middle;
    } else {
      left = middle + 1;
    }
  }
  cout << left - 2 << endl;
  return 0;
}
