#include <bits/stdc++.h>
int main() {
  int n, k;
  std::cin >> n >> k;
  std::vector<std::pair<int, int>> s;
  for (int i = 0; i < n; ++i) {
    int a, b;
    std::cin >> a >> b;
    s.push_back(std::make_pair(a, b));
  }
  std::sort(s.begin(), s.end());
  std::priority_queue<int, std::vector<int>, std::greater<int>> ends;
  int start;
  int c = 0;
  std::vector<std::pair<int, int>> o;
  for (int i = 0; i < n; ++i) {
    int begin = s[i].first;
    while (!ends.empty() && ends.top() < begin) {
      if (c == k) {
        o.push_back(std::make_pair(start, ends.top()));
      }
      ends.pop();
      --c;
    }
    ++c;
    if (c == k) {
      start = begin;
    }
    ends.push(s[i].second);
  }
  while (!ends.empty()) {
    if (c == k) {
      o.push_back(std::make_pair(start, ends.top()));
    }
    ends.pop();
    --c;
  }
  std::cout << o.size() << std::endl;
  for (size_t i = 0; i < o.size(); ++i) {
    std::cout << o[i].first << ' ' << o[i].second << '\n';
  }
}
