import itertools

N,K = map(int,input().split())
plist = list(map(int,input().split()))

minprice = sum(plist)
sumlist =[]
for v in itertools.permutations(plist, K):
  sumlist.append(sum(v))
print (min(sumlist))