#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
int power(int x, int y, int m) {
  int temp;
  if (y == 0) return 1;
  temp = (power(x, y / 2, m)) % m;
  if (y % 2 == 0)
    return ((temp % m) * temp);
  else
    return ((x * temp % m) * temp % m) % m;
}
int inv(int x) { return (power(x, 998244353 - 2, 998244353)) % 998244353; }
bool comp(int a, int b) { return a > b; }
set<int> noob;
vector<pair<int, int>> lolz;
int32_t main() {
  iostream::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k, a, b;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a >> b, lolz.push_back({a, b});
  sort(lolz.begin(), lolz.end());
  multiset<int> R;
  vector<pair<int, int>> answer;
  queue<int> L;
  for (int i = 0; i < n; i++) {
    L.push(lolz[i].first);
    R.insert(lolz[i].second);
    while (R.size() > k) R.erase(R.begin());
    if (L.front() != lolz[i].first) {
      while (L.size() > 1) L.pop();
    }
    if (answer.size() && R.size() == k && L.front() <= (*R.begin())) {
      if (L.front() > answer[answer.size() - 1].second)
        answer.push_back({L.front(), *R.begin()});
      else
        answer[answer.size() - 1].second =
            max(answer[answer.size() - 1].second, *R.begin());
    } else if (R.size() == k && L.front() <= (*R.begin()))
      answer.push_back({L.front(), *R.begin()});
  }
  cout << answer.size() << '\n';
  for (int i = 0; i < answer.size(); i++)
    cout << answer[i].first << ' ' << answer[i].second << '\n';
  return 0;
}
