#include <bits/stdc++.h>
using namespace std;
static const double PI = 6 * asin(0.5);
static const int INF = 1 << 24;
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
  v.assign(a, vector<T>(b, t));
}
long long all[1000100 - 1], part[1000100 - 1];
void add(int a, int b, int x, int k, int l, int r) {
  if (a <= l && r <= b) {
    all[k] += x;
  } else if (l < b && a < r) {
    part[k] += (min(b, r) - max(a, l)) * x;
    add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    add(a, b, x, k * 2 + 2, (l + r) / 2, r);
  }
}
long long sum(int a, int b, int k, int l, int r) {
  if (r <= a || b <= l) {
    return 0;
  }
  if (a <= l && r <= b) {
    return all[k] * (r - l) + part[k];
  } else {
    long long res;
    res = (min(b, r) - max(a, l)) * all[k];
    res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
    res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
    return res;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  for (int(i) = (0); (i) < ((n)); ++(i)) {
    int a, b;
    cin >> a >> b;
    add(a, b + 1, 1, 0, 0, 100005);
  }
  int ans = 0;
  for (int(i) = (0); (i) < ((100005)); ++(i)) {
    long long t = sum(i + 1, i + 2, 0, 0, 100005);
    if (i + 1 <= (int)t) {
      ans = max(ans, i);
    }
  }
  cout << ans << endl;
}
