Dynamic array#11672

Dynamic array

1 second
128 megabytes
Medium

The teacher writes numbers a_1, a_2, ..., a_n on the board. Then, until the count of numbers written on the board reaches , the students approach the board one by one, choose any two consecutive numbers currently written on the board, and write the sum of these two numbers between them.

Find the smallest possible value of the largest number written on the board.

Input

The first line contains two integers and m~(2 \le n \le m \le 10^5). The next line contains integers a_1, a_2, ..., a_n~(1 \le a_i \le 10^6).

Output

Print the smallest possible value of the largest number written on the board.

Examples

Example 1.

1, 1 β†’ 1, 𝟐, 1 β†’ 1, πŸ‘, 2, 1 β†’ 1, 3, 2, πŸ‘, 1

Example 2.

4, 6, 3 β†’ 4, 6, πŸ—, 3

Example 1

Loading
Loading

Example 2

Loading
Loading

Example 3

Loading
Loading