import itertools
N, K = map(int, input().split())
p = [int(n) for n in input().split()]
p = list(itertools.combinations(p, K))
min = 0
for i in range(K):
    min += p[0][i]
for i in range(len(p)):
    a = 0
    for j in range(K):
        a += p[i][j]
        if a > min:
            break
    if a < min:
        min = a
print(min)