#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a, b, res;
  signed int invite[100000] = {0};
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    invite[a - 1]++;
    invite[b]--;
    for (int j = 0; j < N + 1; j++) cout << invite[j] << endl;
    ;
  }
  signed int sum = 0;
  for (int i = 0; i < 100000; i++) {
    sum += invite[i];
    if (i <= sum) res = i;
  }
  cout << res << endl;
}
