#include <bits/stdc++.h>
using namespace std;
int ruisekiwa[100005];
int main() {
  int a;
  cin >> a;
  for (int b = 0; b < a; b++) {
    int c, d;
    scanf("%d%d", &c, &d);
    ruisekiwa[c]++;
    ruisekiwa[d + 1]--;
  }
  int k = 1;
  int MAX = 0;
  for (int i = a + 1; i >= 0; i++) {
    k += ruisekiwa[i];
    if (k >= i) {
      cout << i - 1 << endl;
      break;
    }
  }
}
