import itertools
 
N = int(input())
K = int(input())
p = list(map(int,input().split(" ")))
lists = []
for l in itertools.combinations(p, K):
  sums = sum(list(l))
  lists.append(sums)
 
print(min(lists))