import itertools

N, K = map(int, input().split())
p = list(map(int, input().split()))
ans = 10e6

for i in itertools.combinations(p, K):
    tmp = sum(list(i))
    if tmp < ans:
        ans = tmp

print(ans)
