import itertools
n,k = map(int,input().split())
p = [int(i) for i in input().split()]
ans = []

combi = list(itertools.combinations(p,k))
for i in range(len(combi)) :
    ans.append(sum(combi[i]))
print(min(ans))