n,k = map(int, input().split())
P = [*map(int, input().split())]
# print(n,k)
# print(P)

ans = 1000000000
for i in range(1<<n):
    # print(bin(i))
    v = []
    for j in range(n):
        if i>>j & 1:
          v.append(P[j])
        if len(v) == k: break
    # print(v)
    if len(v) == k:
        ans = min(ans, sum(v))
print(ans)
