Sugoroku

Squares 2 to N+1 are each marked 0 or 1; find the smallest die size j such that some sequence of rolls from 1 to j reaches or passes square N+2 without landing on any square marked 1.

Medium5Dynamic programmingBFSGraphGreedyInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

JOI found a sugoroku board at his uncle's house. The board is a line of N+2N+2 squares. Square 1 is the start and square N+2N+2 is the goal. Every other square has either 0 or 1 written on it, and for each ii (1iN1 \le i \le N) the number written on square i+1i+1 is AiA_i.

The game begins with the piece on the start square. After that, you repeat one action: roll the die and move the piece forward by the number rolled. If the piece stops on a square with 1 written on it, the game is over. If the piece never stops on a square with 1 and it either stops exactly on the goal square or moves past the goal square, the game is cleared.

JOI went to a toy shop to buy a die for the game. The shop sells N+1N+1 dice. Die jj (1jN+11 \le j \le N+1) has jj faces, with 1,2,,j1, 2, \dots, j written one per face.

Among the dice for which some sequence of rolls clears the game, JOI buys the one with the fewest faces. Which die should he buy?

Input

The input is given from standard input in the following format.

N
A_1 A_2 ... A_N

Output

Print the number of faces of the die JOI should buy, on one line.

Constraints

  • 1N1001 \le N \le 100
  • 0Ai10 \le A_i \le 1 (1iN1 \le i \le N)