#include <bits/stdc++.h>
using namespace std;
pair<int, int> friends[100000];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> friends[i].first >> friends[i].second;
  }
  int max_num = 1;
  for (int i = 2; i <= 100001; ++i) {
    int num = 1;
    for (int j = 0; j < N; ++j) {
      if (friends[j].first <= i && i <= friends[j].second) {
        num++;
      }
    }
    if (num >= i) max_num = i;
  }
  cout << max_num - 1 << endl;
  return 0;
}
