#000406

SIO-Knjige

Jack the book worm likes it best when shelves with books are tidy, so he sometimes puts them in order during the night. He is tiny, but very strong. When he has eaten, he can easily carry more books.One evening he found a pile of books at the middle of the shelf. Each of the books has it's position on the shelf. Let's designate the position where Jack found the books with 0. Positive integers will be the positions right from the place where he is, and negative ones will be left. In order to travel from one position to another, Jack has to make a footstep. The length he passed is counted with the numbers of steps he had to make to put all the books in order. For example, if Jack carries two books and has to put them on the positions 3 and 5, he has to make 10 steps, because he has to go to position 5 and to return to position 0, and will place the book "3" while on his way to position 5. Whenever Jack returns to position 0, he mustn't carry any books. Write a program which calculates the minimal route Jack has to travel in order to put all books in order.



Input Input: The first line of standard input contains positive integer M (0<M<=10000) which designates the number of books Jack can carry at a time. The second line of standard input contains a positive integer N which is the number of books Jack has to move from position 0 to the corresponding position. The next N lines contain one integer each and designate the position on which the book should be.

Output Output: The only line of the standar output contains a positive integer equal to the minimal route jack has to travel in order to put all books in the designated positions.

Input:
2
8
1
0
10
-2
5
-4
2
-5

Output:
38

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.