import itertools
 
S = list(map(int, input().strip().split()))
N = S[0]
K = S[1]
p = list(map(int, input().strip().split()))
lists = [1000000000000]
x = list(itertools.combinations(p, K))
counts = len(list(x))
for l in range(1,x+1):
    sums = sum(list(x[counts - 1]))
    if int(sums) <= int(lists[l-1]):
        lists.append(sums)
    else:
        continue

print(min(lists))