#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double PI = acos(-1);
const double EPS = 1e-8;
int a[100000];
int b[100000];
template <class T>
T upper_search(T lb, T ub, bool (*C)(T)) {
  while (ub - lb > 1) {
    T mid = (lb + ub) / 2;
    if (C(mid))
      lb = mid;
    else
      ub = mid;
  }
  return lb;
}
int n;
bool C(int c) {
  int hoge = 0;
  for (int i = 0; i < (int)n; ++i) {
    if (a[i] <= c + 1 && c + 1 <= b[i]) hoge++;
    if (hoge == c) return 1;
  }
  return 0;
}
int main() {
  while (cin >> n) {
    for (int i = 0; i < (int)n; ++i) cin >> a[i] >> b[i];
    cout << upper_search(0, 100005, C) << endl;
  }
}
