n, k = map(int, input().split())
p = list(map(int, input().split()))

import itertools

comb = list(itertools.combinations(p, k))

ans = 100000000000
for i in range(len(comb)):
    ans = min(ans, sum(comb[i]))

print(ans)
    