#include <bits/stdc++.h>
using namespace std;
int N;
int D[100005];
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    D[a]++;
    D[b + 1]--;
  }
  D[0]++;
  int res = 0;
  for (int i = 1; i <= N; i++) {
    D[i] = D[i] + D[i - 1];
    if (D[i] >= i) res = i;
  }
  cout << res - 1 << endl;
}
