import itertools
ans = 10000000000000000000000000000000000
n, k = map(int, input(). split())
p = list(map(int, input(). split()))
P = list(itertools.combinations(p, k))
s = len(P)
for i in range(s):
  P[i] = list(P[i])
  q = sum(P[i])
  if ans >= q:
    ans = q
print(ans)