#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;
struct info {
  long long int min;
  long long int max;
  bool flg = true;
};
bool info_first(const info& a, const info& b) { return a.min > b.min; }
bool info_second(const info& a, const info& b) { return a.max < b.max; }
signed main() {
  (cin >> n);
  vector<info> P(n);
  for (long long int i = 0; i < n; i++) {
    (cin >> P[i].min >> P[i].max);
  }
  sort(P.begin(), P.end(), info_first);
  long long int ans = n + 1;
  for (long long int i = 0; i < n; i++) {
    if (P[i].min > ans) {
      ans--;
      P[i].flg = false;
    }
  }
  sort(P.begin(), P.end(), info_second);
  for (long long int i = 0; i < n; i++) {
    if (P[i].flg and P[i].max < ans) {
      ans--;
    }
  }
  (cout << ans - 1 << endl);
  return 0;
}
