#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (auto& x : vec) is >> x;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (long long i = 0; i < (vec.size()); i++) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<vector<T> >& vec) {
  for (long long i = 0; i < (vec.size()); i++) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  long long n;
  cin >> n;
  map<long long, long long> m;
  for (long long i = 0; i < (n); i++) {
    long long a, b;
    cin >> a >> b;
    m[a]++;
    m[b + 1]--;
  }
  long long ans = 1;
  long long cnt = 1;
  for (auto& p : m) {
    long long need, d;
    tie(need, d) = p;
    cnt += d;
    if (cnt >= need) {
      ans = max(ans, need);
    }
  }
  cout << ans - 1 << endl;
}
