import itertools

n, k = map(int, input().split())
lst = [int(i) for i in input().split()]

lists = list(itertools.combinations(range(n), k))
#print(lists)
min_price = float('inf')
for each in lists:
  total = 0
  for index in each:
    total += lst[index]
  if total < min_price:
    min_price = total
print(min_price)