N, K = map(int, input().split())
p = list(map(int, input().split()))
n = len(p)
ans = 10 ** 9

for i in range(2 ** n):
    total = 0
    cnt = 0
    for j in range(n):
        if((i >> j) & 1):
            total += p[j]
            cnt += 1
    if cnt == K and ans > total:
        ans = total
print(ans)