import itertools
N, K = map(int, input().split())
P = list(map(int, input().split()))
B = list(itertools.combinations(P, K))
ans = 1001
if N == 1:
    print(P[0])
    exit(0)
for b in B:
    if ans > sum(b):
        ans = sum(b)
print(ans)