#include <bits/stdc++.h>
using namespace std;
template <typename T>
T& max(T& a, T& b) {
  if (a >= b) return a;
  return b;
}
template <typename T>
T& min(T& a, T& b) {
  if (a < b) return a;
  return b;
}
template <typename T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
T get() {
  T a;
  cin >> a;
  return a;
}
template <typename T>
T rev(T a) {
  reverse(a.begin(), a.end());
  return a;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (long long i = 0; i < (vec.size()); ++i) is >> vec[i];
  return is;
}
template <typename T>
vector<T>& sort(vector<T>& a) {
  sort(a.begin(), a.end());
  return a;
}
const long long inf = 1e9;
const long long linf = 3e18;
const double eps = 1e-9;
long long imos[100005];
signed main() {
  long long N;
  cin >> N;
  for (long long i = 0; i < (N); ++i) {
    long long a, b;
    cin >> a >> b;
    imos[a]++, imos[b + 1]--;
  }
  for (long long i = 0; i < (100005); ++i)
    if (i) imos[i] += imos[i - 1];
  long long ma = 1;
  for (long long i = 0; i < (100005); ++i) {
    if (imos[i] >= i) ma = i;
  }
  cout << ma - 1 << endl;
}
