#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[100002] = {0}, b[100002] = {0};
  int temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    a[temp - 1]++;
    cin >> temp;
    b[temp]++;
  }
  int ans = 0;
  for (int i = 100001; i > 0; i--) {
    ans = ans + b[i] - a[i];
    if (ans >= i) {
      cout << i - 1 << endl;
      break;
    }
  }
  cout << 0 << endl;
  return 0;
}
