#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int N = 2000010;
struct Event {
  int type, x;
  Event() : type(), x() {}
  Event(int _type, int _x) : type(_type), x(_x) {}
  bool operator<(const Event &e) const {
    if (x != e.x) return x < e.x;
    return type < e.type;
  }
} ev[N];
int n, k;
int ans[N][2];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    ev[2 * i] = Event(0, l);
    ev[2 * i + 1] = Event(1, r);
  }
  n *= 2;
  sort(ev, ev + n);
  int L = inf, Sz = 0;
  for (int i = 0; i < n; i++) {
    if (ev[i].type == 0) {
      k--;
      if (k == 0) L = ev[i].x;
    } else {
      k++;
      if (k == 1) {
        ans[Sz][0] = L;
        ans[Sz][1] = ev[i].x;
        Sz++;
        L = inf;
      }
    }
  }
  printf("%d\n", Sz);
  for (int i = 0; i < Sz; i++) printf("%d %d\n", ans[i][0], ans[i][1]);
  return 0;
}
