from itertools import combinations

N,K = map(int, input().split())
P = list(map(int, input().split()))

ans = 100000000
for tup in combinations(P, K):
    price = sum(tup)
    ans = min(price,ans)
print(ans)