import itertools

N, K = map(int, input().split())
P = list(map(int, input().split()))

# tmp = itertools.combinations_with_replacement(P, K)
tmp = itertools.combinations(P, K)

hoge = []
for i in tmp:
    hoge.append(sum(i))

print(min(hoge))
