import itertools
 
S = list(map(int, input().strip().split()))
N = S[0]
K = S[1]
p = list(map(int, input().strip().split()))
lists = []
for l in list(itertools.combinations(p, K)):
  sums = sum(list(l))
  lists.append(sums)

print(min(lists))