#include <bits/stdc++.h>
int i[100012], d[100012];
int main() {
  int n, a, x, y;
  int ans = 0, now = 1;
  scanf("%d", &n);
  for (a = 0; a < n; a++) {
    scanf("%d%d", &x, &y);
    i[x]++;
    d[y]++;
  }
  for (a = 2; a <= n + 1; a++) {
    printf("%d %d\n", a, now);
    now += i[a];
    if (now >= a) ans = a - 1;
    now -= d[a];
  }
  printf("%d\n", ans);
  exit(0);
}
