#include <bits/stdc++.h>
using namespace std;
int s[100010], n;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    ++s[a];
    --s[b + 1];
  }
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    s[i] += s[i - 1];
    if (s[i] == i) res = i - 1;
  }
  cout << res << endl;
}
