
import itertools

[n,k] = [int(x) for x in input().split()]
data = [int(x) for x in input().split()]

kumi = list(itertools.combinations(list(range(n)), k))
answer = sum(data)

for comb in kumi:
    total = 0
    for x in comb:
        total += data[x]
    if total < answer:
        answer = total

print(answer)

