from itertools import combinations
n,k = map(int,input().split())
P = list(map(int,input().split()))

ans = float('inf')
for t in combinations(range(n),k):
    res = 0
    for i in range(k):
        res+=P[t[i]]
    ans = min(res,ans)
    
print(ans)