#include <bits/stdc++.h>
using namespace std;
const int N = 2010000;
struct node {
  int x, type;
  bool operator<(node T) const {
    if (x == T.x) return type < T.type;
    return x < T.x;
  }
} a[N];
int n, k, sz = 0;
stack<int> q;
vector<pair<int, int> > ans;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    a[++sz].x = l, a[sz].type = 0;
    a[++sz].x = r, a[sz].type = 1;
  }
  sort(a + 1, a + 1 + sz);
  for (int i = 1; i <= sz; ++i) {
    if (a[i].type == 0) {
      q.push(i);
    } else {
      if ((int)q.size() >= k) {
        int from = q.top();
        while ((int)ans.size() > 0 && from <= ans[(int)ans.size() - 1].first)
          ans.pop_back();
        ans.push_back(make_pair(from, i));
      }
      q.pop();
    }
  }
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)ans.size(); ++i) {
    printf("%d %d\n", a[ans[i].first].x, a[ans[i].second].x);
  }
  return 0;
}
