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