#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;
int a[MAX_N], b[MAX_N];
int n;
int imos[MAX_N];
int sch[MAX_N];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    imos[a[i]]++;
    imos[b[i] + 1]--;
  }
  for (int i = 0; i < 6; ++i) {
    cout << imos[i] << "\n";
  }
  sch[0] = imos[0];
  for (int i = 0; i < 100002; ++i) {
    sch[i + 1] = sch[i] + imos[i + 1];
  }
  int res = -1;
  for (int i = 0; i < 100002; ++i) {
    if (sch[i] >= i - 1 && i > res) {
      res = i;
    }
  }
  cout << res - 1 << "\n";
}
