There are stones in a line with the -th stone having a height of .
There is a toad who is initially on the first stone. He will repeat the following action some number of times to reach the last stone:
- If the toad is currently on stone , jump to any one of stone , , , . Here, a cost of is incurred, where is the stone the toad lands on.
Find the minimum total cost required for the toad to reach the last stone.
Constraints
For all subtasks,
Subtask 1 [50%]
Subtask 2 [50%]
No additional constraints.
Input Specification
The first line of input will contain and .
The next line will contain space-separated integers .
Output Specification
Output one integer, the minimum total cost required for the toad to reach the last stone.
Sample Input
6 2
1 5 4 5 2 5
Sample Output
4
Explanation for Sample Output
The toad can jump from stone to stone , then to stone and finally to stone .
Comments