#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, inf = 2e9;
int n, k, arr[N];
pair<int, int> P[N];
bool compare(int P1, int P2) { return P1 <= P2; }
void _merge(int l, int mid, int r, vector<int>& V) {
  int L = l, R = mid, inx = L;
  while (L < mid && R < r) {
    if (compare(V[L], V[R])) {
      arr[inx++] = V[L++];
    } else
      arr[inx++] = V[R++];
  }
  while (L < mid) {
    arr[inx++] = V[L++];
  }
  while (R < mid) {
    arr[inx++] = V[R++];
  }
  for (int i = l; i < r; i++) {
    V[i] = arr[i];
  }
}
void _sort(int l, int r, vector<int>& V) {
  if (r <= l + 1) return;
  int mid = (l + r) / 2;
  _sort(l, mid, V);
  _sort(mid, r, V);
  _merge(l, mid, r, V);
}
void read_input() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> P[i].first >> P[i].second;
  }
}
void solve() {
  vector<int> bg, en;
  for (int i = 0; i < n; i++)
    bg.push_back(P[i].first), en.push_back(P[i].second);
  sort(bg.begin(), bg.end()), sort(en.begin(), en.end());
  int i = 0, j = 0, cnt = 0;
  pair<int, int> ans = {inf, inf};
  vector<pair<int, int> > V;
  while (i < n || j < n) {
    if (j == n || (bg[i] <= en[j] && i < n)) {
      cnt++;
      if (cnt == k) {
        ans.first = bg[i];
      }
      if (cnt >= k) ans.second = bg[i];
      i++;
    } else if (i == n || (en[j] < bg[i] && j < n)) {
      if (cnt == k) {
        ans.second = en[j];
        V.push_back(ans);
      }
      cnt--;
      j++;
    }
  }
  cout << (int)V.size() << '\n';
  for (auto it : V) cout << it.first << ' ' << it.second << '\n';
}
void write_output() {}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int test_cases = 1;
  while (test_cases--) {
    read_input(), solve(), write_output();
  }
  return 0;
}
