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