题库练习 Exams
← 上一题 下一题 →

A9568 | Exams

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly $n$ exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.

According to the schedule, a student can take the exam for the $i$ -th subject on the day number $a_{i}$ . However, Valera has made an arrangement with each teacher and the teacher of the $i$ -th subject allowed him to take an exam before the schedule time on day $b_{i}$ ( $b_{i}<a_{i}$ ). Thus, Valera can take an exam for the $i$ -th subject either on day $a_{i}$ , or on day $b_{i}$ . All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number $a_{i}$ .

Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date.

输入格式

Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly $n$ exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.

According to the schedule, a student can take the exam for the $i$ -th subject on the day number $a_{i}$ . However, Valera has made an arrangement with each teacher and the teacher of the $i$ -th subject allowed him to take an exam before the schedule time on day $b_{i}$ ( $b_{i}<a_{i}$ ). Thus, Valera can take an exam for the $i$ -th subject either on day $a_{i}$ , or on day $b_{i}$ . All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number $a_{i}$ .

Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date.

输出格式

Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.

输入输出样例

输入 #1
3
5 2
3 1
4 2
输出 #1
2
输入 #2
3
6 1
5 2
4 3
输出 #2
6
C++ 编辑器
输入
输出