from itertools import combinations

N,K=list(map(int, input().split()))
P=list(map(int, input().split()))
ans=float('INF')
L=list(combinations(range(N),K))
for a in L:
    sums=0
    for i in range(K):
        sums+=P[a[i]]
    # print(sums)
    ans=min(ans,sums)
print(ans)