N,K = map(int,input().split())
p = list(map(int,input().split()))
result = 1000000000000000000000000

for i in range(2 ** N):
    bit = []
    total = 0
    
    for j in range(N):
        if ((i>>j) & 1):
            bit.append(p[j])
            total += p[j]
    if len(bit) == K:
        if sum(bit) < result:
            result = sum(bit)
print(result)
    