The algorithmic games in NlogNsglow open with a demolition demonstration: a row of tower blocks comes down in front of the crowd. The original plan was one controlled explosion per block, but there is no longer enough time for that.
To clear the blocks faster you get to use a Universal Kinetic / Incandescent Energy Particle Cannon (UKIEPC). One charge does one of two things.
In the second case a block with fewer than x floors is left untouched. In a block with more than x floors, every floor above the removed x-th one falls down by one level.
Given the height of every block, find the minimum number of charges that removes all floors of all blocks.
The first line contains the number of blocks n, where 2≤n≤100000.
The second line contains the block heights h1,h2,…,hn in order from left to right, where 1≤hi≤1000000.
Print one line with one integer: the minimum number of charges needed to tear down all the blocks.