#include <bits/stdc++.h>
using namespace std;
class Sum {
  int n;
  vector<int> data;
  void query(int a, int b, int k, int l, int r, int x) {
    if (r < a || b < l) return;
    if (a <= l && r <= b)
      data[k] += x;
    else {
      query(a, b, k * 2 + 1, l, (l + r) / 2, x);
      query(a, b, k * 2 + 2, (l + r + 1) / 2, r, x);
    }
  }

 public:
  Sum(int n0) {
    n = 1;
    while (n < n0) n *= 2;
    data.assign(2 * n - 1, 0);
  }
  void add(int a, int b, int x) { query(a, b, 0, 0, n - 1, x); }
  int get(int k) {
    k += n - 1;
    int ret = data[k];
    while (k > 0) {
      k = (k - 1) / 2;
      ret += data[k];
    }
    return ret;
  }
};
int main() {
  int n;
  cin >> n;
  Sum sum(n + 1);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    sum.add(a, b, 1);
  }
  int i = n + 1;
  for (;;) {
    if (sum.get(i) >= i - 1) {
      cout << (i - 1) << endl;
      break;
    }
    --i;
  }
  return 0;
}
