#include <bits/stdc++.h>
const int maxn = 2000000 + 10;
using namespace std;
int A, B, Count = 0;
int num[maxn], tmp[maxn];
int dict[2 * maxn];
int sigx[maxn], sigy[maxn];
int main() {
  scanf("%d%d", &A, &B);
  for (int i = 1; i <= 2 * A; i += 2) {
    scanf("%d%d", &num[i], &num[i + 1]);
    tmp[i] = num[i], tmp[i + 1] = num[i + 1];
  }
  sort(tmp + 1, tmp + 1 + 2 * A);
  int L = unique(tmp + 1, tmp + 2 * A + 1) - tmp - 1;
  for (int i = 1; i <= 2 * A; i += 2) {
    int x = lower_bound(tmp + 1, tmp + L + 1, num[i]) - tmp;
    int y = lower_bound(tmp + 1, tmp + L + 1, num[i + 1]) - tmp;
    dict[2 * x - 1]++, dict[2 * y]--;
  }
  for (int i = 2; i <= 2 * L; i++) dict[i] = dict[i - 1] + dict[i];
  int x = -1, y = -1;
  for (int i = 1; i <= 2 * L; i++) {
    if (dict[i] >= B && x == -1) x = i;
    if (dict[i] < B && x != -1) {
      y = i;
      sigx[Count] = tmp[(x + 1) / 2], sigy[Count++] = tmp[y / 2];
      x = -1;
    }
  }
  printf("%d\n", Count);
  for (int i = 0; i < Count; i++) printf("%d %d\n", sigx[i], sigy[i]);
}
