/*
* File: pku1089.cpp
* Author: chenjiang
*贪心算法+排序
* Created on 2010年4月18日, 下午2:29
*/
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define _max 50005
struct node {
int start, end;
} a[_max];
int n;
int cmp(const void *p1, const void *p2) {
struct node *c = (struct node *) p1;
struct node *d = (struct node *) p2;
if (c->start != d->start) return c->start - d->start;
else return d->end - c->end;
}
/*
*
*/
int main(int argc, char** argv) {
//freopen("a.txt", "r", stdin);
while (cin >> n) {
for (int i = 0; i < n; i++) {
cin >> a[i].start >> a[i].end;
}
qsort(a, n, sizeof (struct node), cmp);
int start, end;
start = a[0].start;
end = a[0].end;
for (int i = 1; i < n; i++) {
if (a[i].start <= end && a[i].end > end) {
end = a[i].end;
}
if (a[i].start > end) {
cout << start << " " << end << endl;
start = a[i].start;
end = a[i].end;
}
}
cout << start << " " << end << endl;
}
return (EXIT_SUCCESS);
}