#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
int a[MAX_N], b[MAX_N];
int n;
bool possible(int u) {
  int cnt = 0;
  if (u == 0) {
    return true;
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] <= u + 1 && b[i] >= u + 1) {
      cnt++;
      if (cnt >= u) {
        return true;
      }
    }
  }
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i], &b[i]);
  }
  int res = -1;
  for (int i = 0; i < n + 1; ++i) {
    if (possible(i) && i > res) {
      res = i;
    }
  }
  cout << res << "\n";
  return 0;
}
