#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<pair<int, pair<int, int> > > v;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    v.push_back({l, {0, i}});
    v.push_back({r, {1, i}});
  }
  int hot[n];
  memset(hot, 0, sizeof(hot));
  sort(v.begin(), v.end());
  vector<pair<int, int> > ans;
  int cnt = 1;
  int prev = v[0].first;
  hot[v[0].second.second] = 1;
  for (int i = 1; i < 2 * n; i++) {
    if (cnt >= k) {
      ans.push_back({prev, v[i].first});
    }
    prev = v[i].first;
    if (hot[v[i].second.second] == 0)
      cnt++;
    else
      cnt--;
    hot[v[i].second.second] = 1 - hot[v[i].second.second];
  }
  int j = 0;
  vector<int> final;
  for (int i = 0; i < ans.size(); i++) {
    if (j == 0) {
      final.push_back(ans[i].first);
      if (i < ans.size() - 1 && ans[i].second == ans[i + 1].first) {
        j = 1;
      } else {
        final.push_back(ans[i].second);
      }
    } else {
      if (i < ans.size() - 1 && ans[i].second == ans[i + 1].first) {
        j = 1;
      } else {
        final.push_back(ans[i].second);
        j = 0;
      }
    }
  }
  if (final.size() == 0) {
    cout << 0;
    return 0;
  }
  cout << final.size() / 2 << endl;
  for (int i = 0; i < final.size() / 2; i++) {
    cout << final[2 * i] << " " << final[2 * i + 1] << endl;
  }
}
