Problem2343--Climbing Takahashi

2343: Climbing Takahashi

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200200 points

Problem Statement

There are NN platforms arranged in a row. The height of the ii-th platform from the left is H_iHi.
Takahashi is initially standing on the leftmost platform.
Since he likes heights, he will repeat the following move as long as possible.
  • If the platform he is standing on is not the rightmost one, and the next platform to the right has a height greater than that of the current platform, step onto the next platform.
Find the height of the final platform he will stand on.

Constraints

  • 2 \leq N \leq 10^52N105
  • 1 \leq H_i \leq 10^91Hi109
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:
NNH_1H1\ldotsH_NHN

Output

Print the answer.

Sample Input Copy

5
1 5 10 4 2

Sample Output Copy

10

HINT

Takahashi is initially standing on the leftmost platform, whose height is 11. The next platform to the right has a height of 55 and is higher than the current platform, so he steps onto it.

He is now standing on the 22-nd platform from the left, whose height is 55. The next platform to the right has a height of 1010 and is higher than the current platform, so he steps onto it.

He is now standing on the 33-rd platform from the left, whose height is 1010. The next platform to the right has a height of 44 and is lower than the current platform, so he stops moving.

Thus, the height of the final platform Takahashi will stand on is 1010.

Source/Category