using namespace std;
struct student{
string ID_number;
string start;
string end;
}S[500];
int n;
bool cmp1(student a,student b)
{
return a.start[HTML_REMOVED]b.end;
}
int main()
{
cin>>n;
for(int i=0;i[HTML_REMOVED]>S[i].ID_number;
cin>>S[i].start;
cin>>S[i].end;
}
sort(S,S+n,cmp1);
cout<<S[0].ID_number<<” “;
sort(S,S+n,cmp2);
cout<<S[0].ID_number;
return 0;
}