#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
using std::cin;
using std::cout;
using std::queue;
using std::vector;
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
const auto ready = []() {
  cin.tie(0);
  cout.tie(0);
  std::ios_base::sync_with_stdio(false);
  return true;
}();
vpii ans;
void merge(vi &l, vi &r, int n, int k) {
  int ptr1 = 0, ptr2 = 0;
  pii cur;
  int curK = 0;
  while (ptr1 < n && ptr2 < n) {
    if (l[ptr1] <= r[ptr2]) {
      ++curK;
      if (curK == k) cur.first = l[ptr1];
      ++ptr1;
    } else {
      --curK;
      if (curK == k - 1) cur.second = r[ptr2], ans.push_back(cur);
      ;
      ++ptr2;
    }
  }
  while (ptr2 < n) {
    --curK;
    if (curK == k - 1) cur.second = r[ptr2], ans.push_back(cur);
    ;
    ++ptr2;
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  vi l(n), r(n);
  for (int i = 0; i < n; ++i) cin >> l[i] >> r[i];
  std::sort((l).begin(), (l).end());
  std::sort((r).begin(), (r).end());
  merge(l, r, n, k);
  cout << ans.size() << "\n";
  for (auto &x : ans) cout << x.first << " " << x.second << "\n";
  return 0;
}
