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