from itertools import combinations
N,K = map(int,input().split())
P = list(map(int,input().split()))

res = 10**16
for t in combinations(range(N), K):
  res = min(res, sum([P[i] for i in t]))
print(res)
