262144#10577

262144

1 second
128 megabytes
Hard

Bessie likes downloading games to play on her cell phone, even though she finds the small touch screen rather cumbersome to use with her large hooves.

She is particularly intrigued by the game she is currently playing. The game starts with a sequence of positive integers, each in the range to . In one move, Bessie can choose two adjacent numbers with equal values and replace them with a single number whose value is one greater. For example, she can replace two adjacent s with an .

The goal is to maximize the value of the largest number present in the sequence at the end of the game. Please help Bessie achieve the highest score possible!

Input

The first line contains an integer n~(2 \le n \le 262144), and the next lines contain the numbers in the initial sequence.

Output

Print the largest integer Bessie can generate.

Examples

In the example shown here, Bessie first merges the second and third s, obtaining the sequence . She then merges the two s to obtain a . Note that it is not optimal to merge the first two s.

Example 1

Loading
Loading