#include <bits/stdc++.h>
const int INF = 100000000;
const double EPS = 1e-10;
const int MOD = 1000000007;
using namespace std;
int n;
int a[100000], b[100000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  int s = 0, e = n + 1, mid;
  while (e - s > 1) {
    mid = (s + e) / 2;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] <= mid && mid <= b[i]) cnt++;
    }
    if (cnt >= mid)
      s = mid;
    else
      e = mid;
  }
  cout << s << endl;
}
