Vous êtes sur la page 1sur 3

Enter | Register

HOME TOP CONTESTS GYM PROBLEMSET GROUPS RATING API HELP LYFT MAILRU CUP CALENDAR

PROBLEMS SUBMIT STATUS STANDINGS CUSTOM TEST

Codeforces Round #274 (Div. 2)


C. Exams Finished
time limit per test: 1 second
memory limit per test: 256 megabytes → Virtual participation
input: standard input
Virtual contest is a way to take part in past
output: standard output contest, as close as possible to participation
on time. It is supported only ACM-ICPC
Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is mode for virtual contests. If you've seen
these problems, a virtual contest is not for
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. you - solve these problems in the archive. If
Besides, he can take several exams on one day, and in any order. you just want to solve some problem from a
contest, a virtual contest is not for you -
solve this problem in the archive. Never use
According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, someone else's code, read the tutorials or
Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an communicate with other person during a
virtual contest.
exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on
day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the Start virtual contest
actual exam and write down the date of the mark as number ai.

Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-
→ Problem tags
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- greedy sortings
decreasing date. No tag edit access

Input
The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. → Contest materials

Announcement
9
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date Tutorial
of the exam in the schedule and the early date of passing the i-th exam, correspondingly.

Output
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.

Examples
input Copy

3
5 2
3 1
4 2

output Copy

input Copy

3
6 1
5 2
4 3

output Copy

Note
In the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the
schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the
schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5).
Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.

In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in
the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Codeforces (c) Copyright 2010-2018 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: Oct/29/2018 17:02:53UTC (d1).
Desktop version, switch to mobile version.
Privacy Policy

Supported by

Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD

Vous aimerez peut-être aussi