#d1207. 拆方块

拆方块

Removing Blocks

Problem Description

There are nn piles of blocks; the ii-th pile is made of hih_i blocks stacked up (see the sample).

Now we remove blocks. A block is called an inner block if and only if its up, down, left and right neighbours are all blocks or the ground; otherwise it is a boundary block. In each operation we remove all boundary blocks.

Find after how many operations all blocks disappear.

Input Format

The first line contains an integer nn (1≤n≤1051 \le n \le 10^5).

The second line contains nn integers hih_i (1≤hi≤1091 \le h_i \le 10^9), the number of blocks in each pile.

Output Format

Output the number of operations needed for all blocks to disappear.

Sample Input

6
2 1 4 6 2 2

Sample Output

3

Sample Explanation

illustration of the block-removal process

Constraints

For all data, 1≤n≤1051 \le n \le 10^5 and 1≤hi≤1091 \le h_i \le 10^9.