#include <bits/stdc++.h>
using namespace std;
vector<int> S(1000000);
vector<pair<int, int> > V;
vector<int> final;
int N, K;
int comp(const void* p1, const void* p2) {
  if (((pair<int, int>*)p1)->first - ((pair<int, int>*)p2)->first > 0)
    return 1;
  else if (((pair<int, int>*)p1)->first - ((pair<int, int>*)p2)->first < 0)
    return -1;
  else {
    if (((pair<int, int>*)p1)->second - ((pair<int, int>*)p2)->second > 0)
      return 1;
    else if (((pair<int, int>*)p1)->second - ((pair<int, int>*)p2)->second < 0)
      return -1;
    else
      return 0;
  }
}
int main() {
  scanf("%d", &N);
  scanf("%d", &K);
  V.resize(2 * N);
  for (int i = 0; i < 2 * N; i++) {
    scanf("%d", &V[i].first);
    if (i % 2 == 0)
      V[i].second = -1;
    else
      V[i].second = 1;
  }
  sort(V.begin(), V.end(), less<pair<int, int> >());
  int size = 0;
  for (int i = 0; i < 2 * N; i++) {
    if (V[i].second == -1) {
      S[size] = V[i].first;
      size++;
      if (size == K) final.push_back(V[i].first);
    } else {
      size--;
      if (size == K - 1) final.push_back(V[i].first);
    }
  }
  size = final.size();
  cout << size / 2 << endl;
  for (int i = 0; i < size; i++) {
    printf("%d", final[i]);
    if (i % 2 == 0)
      printf(" ");
    else
      printf("\n");
  }
  return 0;
}
