import itertools
prod = functools.partial(functools.reduce, operator.mul)
n,k=map(int,input().split())
price=list(map(int,input().split()))

n_list=[]
for com in itertools.combinations(price,k):
    s=sum(com)
    n_list.append(s)
print(min(n_list))