#include <bits/stdc++.h>
struct Range {
  int beg;
  int end;
};
int main(void) {
  int n;
  std::cin >> n;
  Range* ps = new Range[n];
  for (int i = 0; i < n; i++) std::cin >> ps[i].beg >> ps[i].end;
  int mps = 1;
  for (int i = 1; i <= n + 1; i++) {
    int cps = 0;
    bool f = false;
    for (int j = 0; j < n; j++) {
      if (i >= ps[j].beg && i <= ps[j].end) {
        cps++;
        if (cps >= i - 1) {
          f = true;
          break;
        }
      }
    }
    if (f) mps = i;
  }
  std::cout << (mps - 1) << '\n';
  system("pause");
  return 0;
}
