from itertools import product, permutations, combinations
import math
N, K = map(int, input().split())
P = list(map(int, input().split()))

ans = math.inf
for pt in combinations(P, K):
    ans = min(ans, sum(pt))

print(ans)
exit()
