//第一题代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5*1e5 + 10;
struct node{
int x,y;
bool operator < (const node &b)const{
if(x == b.x) return y > b.y;
return x > b.x;
}
}T[maxn];
node tmp[maxn];
int main(){
int n,cnt = 0;
scanf("%d",&n);
for(int i = 0; i < n; i++)
scanf("%d%d",&T[i].x,&T[i].y);
sort(T,T+n);
int tmp_y = -1;
for(int i = 0; i < n; i++){
if(T[i].y >= tmp_y){
tmp[cnt].x = T[i].x;
tmp[cnt].y = T[i].y;
tmp_y = T[i].y;
cnt++;
}
}
for(int i = cnt-1; i >= 0; i--){
printf("%d %d\n",tmp[i].x,tmp[i].y);
}
}