#include <bits/stdc++.h>
char _inp[4097], *_pinp = _inp;
char _;
bool _ssign;
using namespace std;
int N, K;
pair<int, int> ev[2000000];
int main() {
  do {
    while ((N = (*_pinp ? *_pinp++
                        : (_inp[fread(_pinp = _inp, 1, 4096, stdin)] = '\0',
                           *_pinp++))) < '-')
      ;
    _ssign = N == '-';
    if (_ssign)
      while ((N = (*_pinp ? *_pinp++
                          : (_inp[fread(_pinp = _inp, 1, 4096, stdin)] = '\0',
                             *_pinp++))) < '0')
        ;
    for (N -= '0';
         '0' <=
         (_ = (*_pinp ? *_pinp++
                      : (_inp[fread(_pinp = _inp, 1, 4096, stdin)] = '\0',
                                                           *_pinp++)));
         N = (N << 3) + (N << 1) + _ - '0')
      ;
    N = _ssign ? -N : N;
  } while (0);
  do {
    while ((K = (*_pinp ? *_pinp++
                        : (_inp[fread(_pinp = _inp, 1, 4096, stdin)] = '\0',
                           *_pinp++))) < '-')
      ;
    _ssign = K == '-';
    if (_ssign)
      while ((K = (*_pinp ? *_pinp++
                          : (_inp[fread(_pinp = _inp, 1, 4096, stdin)] = '\0',
                             *_pinp++))) < '0')
        ;
    for (K -= '0';
         '0' <=
         (_ = (*_pinp ? *_pinp++
                      : (_inp[fread(_pinp = _inp, 1, 4096, stdin)] = '\0',
                                                           *_pinp++)));
         K = (K << 3) + (K << 1) + _ - '0')
      ;
    K = _ssign ? -K : K;
  } while (0);
  int a, b;
  for (int i = 0; i < N; i++) {
    do {
      while ((a = (*_pinp ? *_pinp++
                          : (_inp[fread(_pinp = _inp, 1, 4096, stdin)] = '\0',
                             *_pinp++))) < '-')
        ;
      _ssign = a == '-';
      if (_ssign)
        while ((a = (*_pinp ? *_pinp++
                            : (_inp[fread(_pinp = _inp, 1, 4096, stdin)] = '\0',
                               *_pinp++))) < '0')
          ;
      for (a -= '0';
           '0' <=
           (_ = (*_pinp ? *_pinp++
                        : (_inp[fread(_pinp = _inp, 1, 4096, stdin)] = '\0',
                                                             *_pinp++)));
           a = (a << 3) + (a << 1) + _ - '0')
        ;
      a = _ssign ? -a : a;
    } while (0);
    do {
      while ((b = (*_pinp ? *_pinp++
                          : (_inp[fread(_pinp = _inp, 1, 4096, stdin)] = '\0',
                             *_pinp++))) < '-')
        ;
      _ssign = b == '-';
      if (_ssign)
        while ((b = (*_pinp ? *_pinp++
                            : (_inp[fread(_pinp = _inp, 1, 4096, stdin)] = '\0',
                               *_pinp++))) < '0')
          ;
      for (b -= '0';
           '0' <=
           (_ = (*_pinp ? *_pinp++
                        : (_inp[fread(_pinp = _inp, 1, 4096, stdin)] = '\0',
                                                             *_pinp++)));
           b = (b << 3) + (b << 1) + _ - '0')
        ;
      b = _ssign ? -b : b;
    } while (0);
    ev[i * 2] = make_pair(a * 2, 1);
    ev[i * 2 + 1] = make_pair(b * 2 + 1, -1);
  }
  sort(ev, ev + 2 * N);
  vector<int> ans;
  int n = 0;
  for (int i = 0, j; i < 2 * N; i = j) {
    for (j = i; j < 2 * N && ev[i].first == ev[j].first; j++) n += ev[j].second;
    if (n >= K && ans.size() % 2 == 0) ans.push_back(ev[i].first);
    if (n < K && ans.size() % 2 == 1) ans.push_back(ev[i].first - 1);
  }
  printf("%d\n", ans.size() / 2);
  for (int i = 0; i < (int)ans.size() / 2; i++)
    printf("%d %d\n", ans[i * 2] / 2, ans[i * 2 + 1] / 2);
  return 0;
}
