#include <bits/stdc++.h>
using namespace std;
struct Tag {
  int min, max;
  bool operator<(const Tag &other) const { return max > other.max; }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  vector<Tag> v(N);
  for (int i = 0; i < N; ++i) {
    cin >> v[i].min >> v[i].max;
    v[i].min--;
    v[i].max--;
  }
  sort(v.begin(), v.end());
  int left = 0, right = N + 1;
  while (left + 1 < right) {
    int n = (left + right) / 2;
    int cnt = 0;
    for (vector<Tag>::iterator it = v.begin(); it != v.end(); ++it) {
      if (it->max < n) break;
      if (it->min <= n) ++cnt;
    }
    if (cnt >= n)
      left = n;
    else
      right = n;
  }
  cout << left << endl;
  return 0;
}
