#P1622. 释放囚犯

释放囚犯

Description

There is a strange prison in the Kingdom of Caima. The prison has PP cells arranged in a line, where the ii-th cell is adjacent to the (i+1)(i+1)-th cell (except for the last one). All cells are currently full.

A release list has been issued from above, requiring one person from the list to be released each day. This frightens the guards, because the PP prisoners can pass messages between adjacent cells. If someone leaves, then the people who could talk to this person will pass the news to everyone they can reach. Everyone who learns about it will become furious and will keep shouting that day, which gives the guards a headache. If you give meat to those who are about to get angry, they will calm down.

Input Format

The first line contains two integers PP and QQ, where QQ is the number of people on the release list.

The second line contains QQ integers, indicating which prisoners to release, guaranteed to be given in increasing order.

Output Format

Output a single line with the minimum total number of person-times of meat deliveries.

20 3
3 6 14

35

Hint

Sample Explanation #1

First release the prisoner in cell 1414: you need to feed the 1919 people in cells 11 to 1313 and 1515 to 2020. Then release the prisoner in cell 66: you need to feed the 1212 people in cells 11 to 55 and 77 to 1313. Finally, release the prisoner in cell 33: you need to feed the 44 people in cells 11 to 22 and 44 to 55.

Constraints

  • For 50%50\% of the testdata, 1P1001 \le P \le 100, 1Q51 \le Q \le 5.
  • For 100%100\% of the testdata, 1P1031 \le P \le 10^3, 1Q1001 \le Q \le 100, QPQ \le P, and the indices of the prisoners to be released are given in increasing order.

Translated by ChatGPT 5