#include <bits/stdc++.h>
typedef struct {
  int l;
  int r;
} array;
typedef struct {
  int ind;
  int num;
} arr;
int cmp(const void *x, const void *y) {
  arr *bx = (arr *)x;
  arr *by = (arr *)y;
  return ((bx->num) - (by->num));
}
int cmp2(const void *x, const void *y) {
  array *ax = (array *)x;
  array *ay = (array *)y;
  return ((ax->l) - (ay->l));
}
array a[1000010], d[4000010];
arr b[2000010];
int s[4000010], f[4000010];
const int m = -1000000001;
int main() {
  int i, j, n, k, now;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &a[i].l, &a[i].r);
    b[i].num = a[i].l;
    b[i].ind = i;
    b[i + n].num = a[i].r;
    b[i + n].ind = i + n;
  }
  qsort(b, 2 * n, sizeof(arr), cmp);
  for (i = 0; i < n * 2; i++) {
    if (i == 0)
      now = 0;
    else {
      if (b[i].num != b[i - 1].num) now += 2;
    }
    if (b[i].ind >= n)
      a[b[i].ind - n].r = now + 1;
    else
      a[b[i].ind].l = now;
    f[now] = b[i].num;
    f[now + 1] = b[i].num;
  }
  now += 2;
  for (i = 0; i < now; i++) s[i] = 0;
  for (i = 0; i < n; i++) {
    s[a[i].l] += 1;
    s[a[i].r] += -1;
  }
  for (i = 1; i < now; i++) s[i] += s[i - 1];
  int sum = 0;
  for (i = 0; i < now; i++) {
    d[i].l = m;
  }
  for (i = 0; i < now; i++) {
    if (s[i] >= k) {
      if (d[sum].l == m)
        d[sum].l = f[i];
      else
        d[sum].r = f[i];
    } else {
      if (d[sum].l != m) {
        d[sum].r = f[i];
        sum++;
      }
    }
  }
  qsort(d, sum, sizeof(array), cmp2);
  printf("%d\n", sum);
  for (i = 0; i < sum; i++) printf("%d %d\n", d[i].l, d[i].r);
  return 0;
}
