#agc024c. [agc024_c]Sequence Growing Easy
[agc024_c]Sequence Growing Easy
Problem Statement
There is a sequence of length , where every element is initially . Let denote the -th element of .
You are given a sequence of length . The -th element of is . Determine if we can make equal to by repeating the operation below. If we can, find the minimum number of operations required.
- Choose an integer such that . Replace the value of with the value of plus .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If we can make equal to by repeating the operation, print the minimum number of operations required. If we cannot, print .
Sample Input 1
4
0
1
1
2
Sample Output 1
3
We can make equal to as follows:
- Choose . becomes .
- Choose . becomes .
- Choose . becomes .
Sample Input 2
3
1
2
1
Sample Output 2
-1
Sample Input 3
9
0
1
1
0
1
2
2
1
2
Sample Output 3
8