#include <bits/stdc++.h>
using namespace std;
typedef struct term {
  int l, u;
} term;
int N;
vector<term> t;
bool search(int n) {
  int count = 0;
  for (int i = 0; i < N; ++i) {
    if (t[i].l - 1 <= n && t[i].u - 1 >= n) {
      count++;
    }
    if (count == n) return true;
  }
  return false;
}
int main() {
  cin >> N;
  int ans = 0;
  t.resize(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d%d", &t[i].l, &t[i].u);
  }
  int min = 1, max = N;
  for (int i = 1; i < N + 1; ++i) {
    if (search(i)) ans = i;
  }
  printf("%d", ans);
  return 0;
}
