#P10948. 升降梯上

升降梯上

Problem Description

After turning on the power of the elevator, the explorers enter the vertical tunnel where the elevator runs. In front of them is a track leading straight to the top of the tower, an elevator parked at the bottom of the track, and a huge lever inside the elevator that controls its movement up and down.

The NescafeˊNescafé Tower has a total of NN floors, and the elevator has a stop on every floor.

The lever has MM control slots. Next to the ii-th slot there is a number CiC_i, satisfying C1<C2<C3<<CMC_1 < C_2 < C_3 < \dots < C_M.

If Ci>0C_i > 0, it means that when the lever is moved to this slot, the elevator will go up CiC_i floors. If Ci<0C_i < 0, it means that when the lever is moved to this slot, the elevator will go down Ci-C_i floors. Also, there is guaranteed to be some Ci=0C_i = 0, and the lever initially stays at this slot.

Note that the elevator can only move within floors 1N1 \sim N. Therefore, it is not allowed to move the lever to a slot that would make the elevator go below floor 11 or above floor NN.

For each floor the elevator moves, it takes 22 seconds. Moving the lever from one control slot to an adjacent slot takes 11 second.

The explorers are currently on floor 11 and want to reach floor NN as quickly as possible. They want to know the minimum time needed to get from floor 11 to floor NN.

Input Format

The first line contains two positive integers N,MN, M.

The second line contains MM integers C1,C2,,CMC_1, C_2, \dots, C_M.

Output Format

Output one integer, the answer: the minimum time required.

If it is impossible to reach, output 1-1.

6 3
-1 0 2
19

Hint

Constraints: It is guaranteed that 1N10001 \le N \le 1000, 2M202 \le M \le 20, N<C1<C2<...<CM<N-N < C_1 < C_2 < ...< C_M < N.

Translated by ChatGPT 5