#include <bits/stdc++.h>
struct hhh {
  int p, o;
} a[2001000];
bool hhhh(hhh q, hhh w) {
  if (q.p != w.p) return q.p < w.p;
  return q.o > w.o;
}
using namespace std;
int b, c, d = 0, e = 2111111111, f = 2111111111, g[1000010][3], ans = 0;
int main() {
  cin >> b >> c;
  for (int m = 1; m <= b; m++) {
    scanf("%d%d", &a[2 * m - 1].p, &a[2 * m].p);
    a[2 * m - 1].o = 1;
    a[2 * m].o = 0;
  }
  sort(a + 1, a + 2 * b + 1, hhhh);
  for (int m = 1; m <= 2 * b; m++) {
    if (a[m].o)
      d++;
    else
      d--;
    if (d >= c && e == 2111111111) e = a[m].p;
    if (d < c && e < 2111111111) {
      g[++ans][0] = e;
      g[ans][1] = a[m].p;
      e = 2111111111;
    }
  }
  printf("%d\n", ans);
  for (int m = 1; m <= ans; m++) printf("%d %d\n", g[m][0], g[m][1]);
}
