import itertools
N,K = map(int,input().split())
P = list(map(int,input().split()))
Sigmas = []
for M in itertools.combinations(P,K):
    Sigma = sum(list(M))
    Sigmas.append(Sigma)
print(min(Sigmas))
