#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
void setIO(string name = "d") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  freopen((name + ".in").c_str(), "r", stdin);
  freopen((name + ".out").c_str(), "w", stdout);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<pi> v(2 * n);
  for (int i = 0; i < 2 * n; i++) {
    int c;
    cin >> c;
    if (i % 2 == 0) {
      v[i] = {c, 0};
    } else {
      v[i] = {c, 1};
    }
  }
  sort(begin(v), end(v));
  vi ans;
  int idx = 0, cur = 0, prev;
  while (idx < 2 * n) {
    int cv = v[idx].first;
    prev = cur;
    if (v[idx].second) {
      cur--;
    } else {
      cur++;
    }
    idx++;
    if ((cur >= k && prev < k) || (cur < k && prev >= k)) {
      ans.push_back(v[idx - 1].first);
    }
  }
  cout << ans.size() / 2 << "\n";
  for (int i = 0; i < ans.size(); i += 2) {
    cout << ans[i] << ' ' << ans[i + 1] << "\n";
  }
}
