Destruction of buildings#9029

Destruction of buildings

1 second
128 megabytes
Easy

There are buildings in Baku that have failed. On their place the new buildings should be built. For this you need to destroy the old buildings.

Barish is a specialist in the destruction of buildings. He has a super-robot that destroys buildings.

There are located next to each other buildings in the city . To destroy them, Barish took advantage of his robot.

Each of the buildings consists of blocks arranged one above the other. The robot must destroy all these blocks. In one move, the robot can destroy all external blocks. From these data, find the number of robot moves to destroy all buildings.

Block is called external, if at least in one of its directions (left, right, down, up) there is an empty space (for clarity, look at the picture)

Input

First line contains the number of buildings (1 \leq n \leq 10^5). Next line contains the heights of buildings h_1, h_2, ... , h_n (1 \leq h_i \leq 10^9).

Output

Print one integer - the number of moves required to destroy all buildings.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Note

Illustration for the first example:

kar.jpg