#include <bits/stdc++.h>
const int INF = 100000000;
const double EPS = 1e-10;
const int MOD = 1000000007;
using namespace std;
int n;
int A = 0, B = INF;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    A = max(A, a);
    B = min(B, b);
  }
  int ans = 0;
  if (A > B || A > n)
    ans = 0;
  else
    ans = min(n, B);
  cout << ans << endl;
}
