#include <bits/stdc++.h>
using namespace std;
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
signed main() {
  int n;
  cin >> n;
  vector<int> v(100010, 0);
  for (int i = (0); i < (n); i++) {
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) v[i]++;
  }
  int ans(0);
  for (int i = (0); i < (v.size()); i++) {
    if (v[i] == i) ans = i;
  }
  cout << max(0, ans - 1) << endl;
  return 0;
}
