import itertools
t = []
N, K = map(int, input().split())
p = [int(i) for i in input().split()]
a = list(itertools.permutations(range(N), K))
for i in range(len(a)):
    s = 0
    for j in range(K):
        s += (p[a[i][j]])
    t.append(s)
print(min(t))