import itertools

N, K = list(map(int, input().split()))
p_n = list(map(int, input().split()))
ans = 10 ** 10

for p in itertools.permutations(p_n, K):
    s = sum(p)
    if ans > s:
        ans = s

print(ans)