import itertools

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

for v in itertools.combinations(p, K):
    tmp = sum(v) 
    if ans > tmp:
        ans = tmp

print(ans)