Opening Ceremony

No attempts yetTime limit1sMemory limit256 MB

Problem

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.

  • Pick a single block and remove all of its floors.
  • Pick a floor number xx and remove the xx-th floor of every block at once.

In the second case a block with fewer than xx floors is left untouched. In a block with more than xx floors, every floor above the removed xx-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.

Input

The first line contains the number of blocks nn, where 2n1000002 \le n \le 100000.

The second line contains the block heights h1,h2,,hnh_1, h_2, \dots, h_n in order from left to right, where 1hi10000001 \le h_i \le 1000000.

Output

Print one line with one integer: the minimum number of charges needed to tear down all the blocks.