#include <bits/stdc++.h>
using namespace std;
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
pair<int, int> a[1000000];
int n;
int search(int m) {
  int c = 0;
  for (int i = 0; i < n; i++) {
    if (a[i].first <= m && m <= a[i].second) c++;
  }
  if (c >= m) return true;
  return false;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int b, c;
    cin >> b >> c;
    a[i] = pair<int, int>(b - 1, c - 1);
  }
  int r = 0, l = 1e9, m;
  while (l - r != 1) {
    m = (r + l) / 2;
    if (search(m))
      r = m;
    else
      l = m;
  }
  cout << r << endl;
}
