import itertools
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))

sum0 = 100100100

for i in itertools.permutations(p, k):
    sum1 = sum(i)
    if sum0 > sum1:
        sum0 = sum1
        
print(sum0)