#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int min_mem = 0, max_mem = 1000000000;
  for (int i = 0; i < N; i++) {
    int aa, bb;
    cin >> aa >> bb;
    min_mem = max(min_mem, aa);
    max_mem = min(max_mem, bb);
  }
  if (min_mem <= N && min_mem <= max_mem) {
    cout << min_mem - 1 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}
