#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a, b;
  vector<pair<int, int> > memo(n);
  for (int(i) = (0); ((i)) < ((n)); ++(i)) {
    scanf("%d%d", &a, &b);
    memo[i] = make_pair(b, a);
  }
  sort(memo.begin(), memo.end());
  int res = 1;
  bool f = true;
  while (f) {
    f = false;
    for (int(i) = (0); ((i)) < ((n)); ++(i)) {
      if (res + 1 >= memo[i].second && res + 1 <= memo[i].first) {
        res++;
        printf("%d %d\n", memo[i].second, memo[i].first);
        memo[i].second = 200000;
        f = true;
        break;
      }
    }
  }
  printf("%d\n", res - 1);
  return 0;
}
