#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 main(void) {
  int n;
  cin >> n;
  int start;
  int end;
  vector<int> table(1e05 + 1 + 1, 0);
  for (int i = 0; i < n; i++) {
    cin >> start >> end;
    start--;
    end--;
    table[start]++;
    table[end]--;
  }
  for (int i = 1; i <= 1e05 + 1; i++) {
    table[i] += table[i - 1];
  }
  for (int i = 1e05 + 1; i >= 0; i--) {
    if (i <= table[i]) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
