N, K = map(int, input().split())

ls = list(map(int, input().split()))
ans = []

for i in range(2**N):
  num = 0
  s = 0
  for j in range(N):
    if ((i >> j) & 1):
      if num < K:
        s += ls[j]
        num += 1
  if num == K:
    ans.append(s)

ans2 = sorted(ans)
print(ans2[0])