#include <bits/stdc++.h>
using namespace std;
int n, d[2000006], k, q, t = 0;
vector<pair<int, int> > axis, g, ans;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    axis.push_back(make_pair(x, i * -1));
    axis.push_back(make_pair(y, i));
  }
  sort(axis.begin(), axis.end());
  int x = 0;
  for (int i = 0; i < n * 2; i++) {
    if (axis[i].second > 0) {
      if (x == k)
        g.push_back(make_pair(q, ++t * -1)),
            g.push_back(make_pair(axis[i].first, t));
      x--;
    } else {
      x++;
      if (x == k) q = axis[i].first;
    }
  }
  sort(g.begin(), g.end());
  t = 0;
  for (int i = 0; i < g.size(); i++) {
    if (g[i].second < 0) {
      t++;
      if (t == 1) q = g[i].first;
    } else {
      t--;
      if (!t) {
        ans.push_back(make_pair(q, g[i].first));
      }
    }
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
  return 0;
}
