import itertools
result = 10000000000000000000
N,K = map(int,input().split())
p = list(map(int,input().split()))
array = list(itertools.combinations(p,K))
#print(list(itertools.combinations(p,K)))

for i in array:
    if sum(i) < result:
        result = sum(i)
print(result)