#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    long long a, b;
    cin >> a >> b;
    mp[a]++;
    mp[b + 1]--;
  }
  int ans = 0;
  int tmp = 0;
  for (auto it : mp) {
    tmp += it.second;
    if (tmp >= it.first - 1) ans = max(ans, it.first - 1);
  }
  cout << ans << endl;
  return 0;
}
