#include <bits/stdc++.h>   using namespace std;   struct node {     int l, r;   } line[1000005];   int a[5000005], ls[5000005], b[5000005];   vector<node> ans;   bool cmp(node a, node b) { return a.l < b.l; }   int main() {     int n, k;     while (~scanf( %d %d , &n, &k)) {       memset(a, 0, sizeof(a));       memset(b, 0, sizeof(b));       ans.clear();       int p = 0;       for (int i = 1; i <= n; i++) {         int l, r;         scanf( %d %d , &l, &r);         line[i] = node{l, r};         ls[++p] = l;         ls[++p] = r;       }       sort(ls + 1, ls + p + 1);       p = unique(ls + 1, ls + p + 1) - (ls + 1);       for (int i = 1; i <= n; i++) {         int l = lower_bound(ls + 1, ls + p + 1, line[i].l) - ls;         int r = lower_bound(ls + 1, ls + p + 1, line[i].r) - ls;         a[l]++;         a[r]--;         b[l]++;         b[r + 1]--;       }       for (int i = 1; i <= p; i++) {         a[i] = a[i - 1] + a[i];         b[i] = b[i - 1] + b[i];       }       for (int i = 0; i <= p; i++) {         if (a[i] >= k) {           int r = i + 1;           while (a[r] >= k) {             r++;           }           ans.push_back(node{ls[i], ls[r]});           i = r - 1;         }         if (a[i - 1] < k && a[i] < k && b[i] >= k) {           ans.push_back(node{ls[i], ls[i]});         }       }       sort(ans.begin(), ans.end(), cmp);       printf( %d n , ans.size());       for (int i = 0; i < (int)ans.size(); i++) {         printf( %d %d n , ans[i].l, ans[i].r);       }     }   }   