#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 9;
struct node {
  int s, p;
} edge[maxn * 2];
int cun[maxn * 2];
bool cmp(node a, node b) {
  if (a.s == b.s) return a.p > b.p;
  return a.s < b.s;
}
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int len = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &edge[len].s, &edge[len + 1].s);
      edge[len++].p = 1;
      edge[len++].p = 0;
    }
    sort(edge, edge + len, cmp);
    int ans = 0;
    int sum = 0;
    for (int i = 0; i < len; i++) {
      if (edge[i].p) {
        sum++;
        if (sum == m) cun[ans++] = edge[i].s;
      } else {
        if (sum == m) cun[ans++] = edge[i].s;
        sum--;
      }
    }
    printf("%d\n", ans / 2);
    for (int i = 0; i < ans; i += 2) printf("%d %d\n", cun[i], cun[i + 1]);
  }
  return 0;
}
