#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
template <class T>
using vt = vector<T>;
template <class T>
using vvt = vector<vector<T>>;
long long gcd(long long n, long long m) { return (m == 0 ? n : gcd(m, n % m)); }
long long lcd(long long n, long long m) { return (n / gcd(n, m) * m); }
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vt<int> imos(100100, 0);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    imos[a]++;
    imos[b + 1]--;
  }
  for (int i = 0; i < n; ++i) imos[i + 1] += imos[i];
  for (int i = n; i >= 1; --i) {
    if (imos[i] + 1 >= i) return cout << i - 1 << endl, 0;
  }
}
