#include <bits/stdc++.h>
using namespace std;
long long int dx[] = {1, -1, 0, 0};
long long int dy[] = {0, 0, 1, -1};
long long int n, m;
long long int a, b;
long long int p, q;
signed main() {
  (cin >> n);
  vector<pair<long long int, long long int>> p(n);
  for (long long int i = 0; i < n; i++) {
    (cin >> p[i].first >> p[i].second);
  }
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());
  long long int ans = n + 1;
  for (long long int i = 0; i < n; i++) {
    if (p[i].first > ans) {
      ans--;
    } else if (p[i].second < ans) {
      ans--;
    }
  }
  (cout << ans - 1 << endl);
  return 0;
}
