#include <bits/stdc++.h>
using namespace std;
int n, k, i, crt;
vector<pair<int, int> > ans, v;
int main() {
  scanf("%d %d", &n, &k);
  for (i = 1; i <= n; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    v.push_back({x, 0});
    v.push_back({y, 1});
  }
  sort(v.begin(), v.end());
  for (auto &it : v) {
    if (it.second == 0)
      crt++;
    else
      crt--;
    if ((ans.size() == 0 || ans.back().second) && crt >= k)
      ans.push_back({it.first, 0});
    else if ((ans.size() && !ans.back().second) && crt < k)
      ans.back().second = it.first;
  }
  printf("%d\n", ans.size());
  for (auto &it : ans) printf("%d %d\n", it.first, it.second);
  return 0;
}
