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

ans = float("inf")
for i in range(1 << len(P)):
    sum = 0
    cnt = 0
    for j in range(len(P)):
        if (i >> j) & 1 == 1:
            sum += P[j]
            cnt += 1
            if cnt == K:
                ans = min(ans, sum)
print(ans)
