#include <bits/stdc++.h>
using namespace std;
int range[100000][2];
int search(int n) {
  int number = n + 1;
  int flag = 1;
  while (flag) {
    flag = 0;
    for (int i = 0; i < n; i++) {
      if (number < range[i][0] || range[i][1] < number) {
        flag = 1;
        break;
      }
    }
    if (!flag) return number - 1;
    number--;
    if (number == 1) return 0;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> range[i][0] >> range[i][1];
  }
  int ans = search(n);
  cout << ans << endl;
  return 0;
}
