#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};
int main() {
  int n;
  cin >> n;
  vector<int> imos(100010, 0);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    imos[a]++;
    imos[b + 1]--;
  }
  for (int i = 0; i < 100008; i++) {
    imos[i + 1] += imos[i];
  }
  int ans = 0;
  for (int i = 0; i < 100006; i++) {
    if (i + 1 == imos[i + 1]) {
      ((ans) = max((ans), (i)));
    }
  }
  cout << ans << endl;
}
