from itertools import combinations as comb

n,k=map(int,input().split())
p=list(map(int,input().split()))

min=None
for x in comb(range(n),k):
    sm=0
    for i in range(len(x)):
        sm+=p[x[i]]
    if not min : min=sm
    if sm<min : min=sm
print(min)