The Lightest Language

No attempts yetTime limit1sMemory limit128 MB

Problem

The alphabet AkA_k consists of the first kk letters of the English alphabet. Each letter is assigned a positive integer weight. The weight of a word built from letters of AkA_k is the sum of the weights of all its letters, and the weight of a language (any finite set of words over AkA_k) is the sum of the weights of all its words.

A language is called prefixless if no word in it is a prefix of another word in it. The goal is to find the smallest possible weight of a prefixless language that has exactly nn words.

For example, let k=2k = 2 with W(a)=2W(a) = 2 and W(b)=5W(b) = 5. Then W(ab)=2+5=7W(ab) = 2 + 5 = 7 and W(aba)=2+5+2=9W(aba) = 2 + 5 + 2 = 9. The language {ab,aba,b}\{ab, aba, b\} is not prefixless, because abab is a prefix of abaaba. The lightest prefixless language with three words over A2A_2 is {b,aa,ab}\{b, aa, ab\}, and its weight is 5+4+7=165 + 4 + 7 = 16.

Given nn, kk, and the weights of the kk letters, compute the minimum weight of a prefixless language of exactly nn words over AkA_k.

Input

The first line contains two integers nn and kk separated by a single space (2n100002 \le n \le 10\,000, 2k262 \le k \le 26): the number of words in the language and the number of letters in the alphabet, respectively.

The second line contains kk positive integers separated by single spaces, each at most 1000010\,000. The ii-th of them is the weight of the ii-th letter.

Output

Print a single integer: the minimum weight of a prefixless language of exactly nn words over the alphabet AkA_k.