#P1027F. Session in BSU
Session in BSU
Description
Polycarp studies in Berland State University. Soon he will have to take his exam. He has to pass exactly exams.
For the each exam there are known two days: — day of the first opportunity to pass the exam, — day of the second opportunity to pass the exam (). Polycarp can pass at most one exam during each day. For each exam Polycarp chooses by himself which day he will pass this exam. He has to pass all the exams.
Polycarp wants to pass all the exams as soon as possible. Print the minimum index of day by which Polycarp can pass all the exams, or print -1 if he cannot pass all the exams at all.
The first line of the input contains one integer () — the number of exams.
The next lines contain two integers each: and (), where is the number of day of the first passing the -th exam and is the number of day of the second passing the -th exam.
If Polycarp cannot pass all the exams, print -1. Otherwise print the minimum index of day by which Polycarp can do that.
Input
The first line of the input contains one integer () — the number of exams.
The next lines contain two integers each: and (), where is the number of day of the first passing the -th exam and is the number of day of the second passing the -th exam.
Output
If Polycarp cannot pass all the exams, print -1. Otherwise print the minimum index of day by which Polycarp can do that.