atcoder#ABC277C. [ABC277C] Ladder Takahashi
[ABC277C] Ladder Takahashi
Score : points
Problem Statement
There is a -story building with ladders. Takahashi, who is on the -st (lowest) floor, wants to reach the highest floor possible by using ladders (possibly none). The ladders are numbered from to , and ladder connects the -th and -th floors. One can use ladder in either direction to move from the -th floor to the -th floor or vice versa, but not between other floors. Takahashi can freely move within the same floor, but cannot move between floors without using ladders. What is the highest floor Takahashi can reach?
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print an integer representing the answer.
4
1 4
4 3
4 10
8 3
10
He can reach the -th floor by using ladder to get to the -th floor and then ladder to get to the -th floor.
6
1 3
1 5
1 12
3 5
3 12
5 12
12
3
500000000 600000000
600000000 700000000
700000000 800000000
1
He may be unable to move between floors.