/* وَقُلْ رَبِّ زِدْنِي عِلْمًاً */
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <fstream>
#include <cctype>
#include <utility>
#define ll long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) ((v).begin()),((v).end())
#define setp(n) cout << fixed << setprecision(n)
#define O_o ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define yes cout << "yes\n"
#define no cout << "no\n"
#define fi(nn) for(ll i = 0; i < (nn); i++)
#define fj(nn) for(ll j = 0; j < (nn); j++)
#define fl(nn) for (ll i = nn - 1; i >= 0; i--)
#define ffij(nn,mm) for(ll i = 0; i < (nn); i++)for(ll j = 0; j < (mm); j++)
#define null NULL
using namespace std;
int main()
{
O_o
ll n, m;
cin >> n >> m;
vector <pair<ll, ll>> v(n), ftra;
fi(n)cin >> v[i].first >> v[i].second;
sort(v.begin(), v.end());
ll mini = v[0].second, maxi = v[0].second;
for (ll i = 1;i < n;i++) {
if (v[i].first <= maxi) {
maxi = max(maxi, v[i].second);
}
else {
ftra.push_back({ mini,maxi });
mini = v[i].first;
maxi = v[i].second;
}
}
ftra.push_back({ mini,maxi });
fi(sz(ftra)) {
cout << ftra[i].first << ' ' << ftra[i].second << '\n';
}
return 0;
}
Lyog2YjZjtmC2Y/ZhNmSINix2Y7YqNmR2ZAg2LLZkNiv2ZLZhtmQ2Yog2LnZkNmE2ZLZhdmL2KfZiyAqLwojaW5jbHVkZSA8aW9zdHJlYW0+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGlvbWFuaXA+CiNpbmNsdWRlIDxzdGFjaz4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8ZGVxdWU+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDx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