#include <bits/stdc++.h>
using namespace std;
void solve() {
  int Digit[100002];
  for (int i = 0; i < 100002; ++i) {
    Digit[i] = 0;
  }
  int N;
  cin >> N;
  vector<pair<int, int> > Person(N);
  for (int i = 0; i < N; ++i) {
    cin >> Person[i].first >> Person[i].second;
  }
  for (int i = 0; i < N; ++i) {
    for (int j = Person[i].first; j <= Person[i].second; ++j) {
      ++Digit[j];
    }
  }
  int Max = 1;
  for (int i = 2; i <= N; ++i) {
    if (Digit[i] >= i) {
      Max = i;
    }
  }
  cout << Max - 1 << endl;
}
int main() {
  solve();
  return (0);
}
