Polycarp studies in Berland State University. Soon he will have to take his exam. He has to pass exactly nnexams.
For the each exam ii there are known two days: aiai — day of the first opportunity to pass the exam, bibi — day of the second opportunity to pass the exam (aibiaibi). 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 nn 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 nn exams, or print -1 if he cannot pass all the exams at all.
The first line of the input contains one integer nn (1≤n≤1061≤n≤106) — the number of exams.
The next nn lines contain two integers each: aiai and bibi (1≤aibi≤1091≤aibi≤109), where aiai is the number of day of the first passing the ii-th exam and bibi is the number of day of the second passing the ii-th exam.
If Polycarp cannot pass all the nn exams, print -1. Otherwise print the minimum index of day by which Polycarp can do that.