#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> p[200100];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[2 * i].first >> p[2 * i + 1].first;
    p[2 * i].second = 0;
    p[2 * i + 1].second = 1;
  }
  p[2 * n] = pair<int, int>(1, 0);
  p[2 * n + 1] = pair<int, int>(100001, 1);
  sort(p, p + 2 * (n + 1));
  int num = 0, cnt = 0, ans = 0;
  for (int i = 0; i <= n + 1; i++) {
    if (p[num].first == i) {
      if (!p[num].second)
        cnt++;
      else
        cnt--;
      if (cnt == i) ans = i;
      num++;
      i--;
    } else if (cnt == i)
      ans = i;
  }
  cout << ans - 1 << endl;
}
