eolymp
bolt
Try our new interface for solving problems
Problems

Space Invaders

Space Invaders

Time limit 1 second
Memory limit 64 MiB

Peter wrote his version of the popular game "Space Invaders". The game is as follows. On the ground attack ships of Space Invaders. They lined up in rows at the top of the screen. The player controls a laser gun, which is located at the bottom of the screen in one of the columns. For one action a player can move the gun left or right, or make a shot straight up. If a player makes a shot, it destroys the alien ship coming in that column, in which the gun.

Unlike the original game, Petya embodiment of alien ships are in place and can not shoot, so the player can not lose. Help the Pete destroy all alien ships in a minimum number of operations.

Input data

The first line contains the number n and p - number of columns and column number, which is initially a gun (1n100, 1pn). The second line contains n numbers a_1, a_2, ..., a_n, where a_i - the number of aliens in the i^th column (1a_i100).

Output data

In the output file output a single number - the minimum number of operations required to destroy all the aliens.

Examples

Input example #1
5 4
5 3 4 1 2
Output example #1
20
Author Georgiy Korneev, Pavel Mavrin