#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > M;
vector<int> A, B;
map<char, char> PLOT;
string str;
vector<pair<int, int> > Range, Qual;
int main() {
  int n, k, i, j;
  cin >> n >> k;
  Range.resize(2 * n);
  Qual.resize(n);
  for (i = 0; i < n; i++) {
    scanf("%d %d\n", &Range[2 * i].first, &Range[2 * i + 1].first);
    Range[2 * i].second = 0;
    Range[2 * i + 1].second = 1;
  }
  sort(Range.begin(), Range.end());
  int ctr;
  ctr = i = 0;
  for (j = 0; j < 2 * n; j++) {
    if (!Range[j].second) {
      ctr++;
      if (ctr == k) Qual[i].first = Range[j].first;
    } else {
      ctr--;
      if (ctr == k - 1) Qual[i++].second = Range[j].first;
    }
  }
  printf("%d\n", i);
  for (j = 0; j < i; j++) {
    printf("%d %d\n", Qual[j].first, Qual[j].second);
  }
  return 0;
}
