Minimum number of Jumps Given a sequence of numbers, find the minimum number of jumps to go from the starting position to the end and come back to the starting position again.

Each element of the sequence denotes the maximum number of moves that one can move from that position.

At any position, you can make a jump of at max k moves, where k is the value stored at that position. After reaching the end, you can use only those positions for jumping which have not been used previously for jumping.

The input will be given as a sequence of numbers separated by single-spaces.
Output should be a single number which is the minimum number of jumps used.
If its not possible to go to the end and come back to the starting position, then print -1

Input:

2 4 2 2 3 4 2 2

Output:

6 (3 to reach end and 3 to come back)

Input

1 0

Output

-1

Note


Assume all the numbers of the sequence are non-negative


EDIT 1

The line "Thus, it should be clear that one can always jump from the last position." might be confusing, so I removed it from the question. It will have no effect on the question.

Winning Criteria :

The winner will be the one with the shortest code.
Mathematica, 197 193 chars
Brute force.
Min[Length/@Select[Join[{1},#,{n},Reverse@#2]&amp;@@@Tuples[Subsets@Range[3,n=Length[i=FromDigits/@StringSplit@InputString[]]]-1,2],{}⋃#==Sort@#∧And@@Thread[i[[#]]≥Abs[#-Rest@#~Append~1]]&amp;]]/.∞-&gt;-1