#include <bits/stdc++.h>
using namespace std;
template <typename T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <typename T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
using ll = long long;
using ld = long double;
const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);
int N;
using pii = pair<int, int>;
int num[100005];
int main() {
  cin >> N;
  vector<pii> req;
  for (int cnt = 0; cnt < (int)(N); cnt++) {
    int a, b;
    cin >> a >> b;
    num[a]++;
    num[b + 1]--;
  }
  num[0]++;
  num[100000]--;
  for (int i = 0; i < (int)(N + 2); i++) num[i + 1] += num[i];
  int res = 0;
  for (int i = 0; i < (int)(N + 2); i++)
    if (num[i] >= i) res = max(res, i);
  cout << res - 1 << endl;
  return 0;
}
