#include <bits/stdc++.h>
using namespace std;
struct node {
  int index, flog;
} num[2000005];
int cmp(node u, node v) {
  if (u.index == v.index) return u.flog > v.flog;
  return u.index < v.index;
}
vector<node> ans, ans2;
int main() {
  int n, a, b, i, k;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    scanf("%d %d", &a, &b);
    node t;
    t.index = a;
    t.flog = 1;
    num[2 * i] = t;
    t.index = b;
    t.flog = -1;
    num[2 * i | 1] = t;
  }
  sort(num, num + 2 * n, cmp);
  int now = 0, index = 0x3f3f3f3f;
  for (i = 0; i < 2 * n; i++) {
    now += num[i].flog;
    if (now == k) {
      if (index == 0x3f3f3f3f) {
        index = num[i].index;
      }
    }
    if (index != 0x3f3f3f3f && now == k - 1) {
      node t;
      t.index = index;
      t.flog = num[i].index;
      ans.push_back(t);
      index = 0x3f3f3f3f;
    }
  }
  if (ans.size() == 0) {
    cout << 0 << endl;
    return 0;
  }
  node now_ = ans[0];
  for (i = 1; i < ans.size(); i++) {
    if (ans[i].index == now_.flog) {
      now_.flog = ans[i].flog;
    } else {
      ans2.push_back(now_);
      now_ = ans[i];
    }
  }
  ans2.push_back(now_);
  cout << ans2.size() << endl;
  for (i = 0; i < ans2.size(); i++) {
    printf("%d %d\n", ans2[i].index, ans2[i].flog);
  }
  return 0;
}
