#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int count[100001] = {0}, ans = 0, sum = 0;
    for (int i = (0); i < (n); i++) {
      int a, b;
      cin >> a >> b;
      a--;
      count[a] += 1;
      count[b] -= 1;
    }
    for (int i = (0); i < (n + 1); i++) {
      sum += count[i];
      if (sum >= i) ans = i;
    }
    cout << ans << endl;
  }
}
