#include <bits/stdc++.h>
using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;
using pii = pair<int, int>;
bool isok(vector<pii>& ab, int n) {
  int acc = 0;
  for (auto&& x : ab) {
    if (x.first <= n && n <= x.second) acc++;
  }
  return acc >= n;
}
int main() {
  int n;
  cin >> n;
  vector<pii> ab(n);
  for (auto&& x : ab) cin >> x.first >> x.second;
  int res = 0;
  bool f = false;
  for (int i = 1; i <= n; i++) {
    if (isok(ab, i + 1)) {
      f = true;
      res = i;
    }
  }
  cout << res << endl;
}
