import itertools
import numpy as np

N, K = input()
que = input()
try:
    N = int(N)
except:
    pass
try:
    K = int(K)
except:
    pass



que = [int(x) for x in que.split()]

#print(que)
"""
tmp = []
for x in que:
    for xx in range(K):
        tmp.append(x)
que = tmp
"""
min_val = 999999999

for x in itertools.combinations(que, K):
    tmp = np.sum(x)
    if tmp < min_val:
        min_val = tmp

print(min_val)
