from itertools import combinations

N, K = map(int, input().split(' '))
fruit_prices = tuple(map(int, input().split(' ')))

min_price = sum(fruit_prices)

for comb in combinations(fruit_prices, K):
  min_price = min(sum(comb), min_price)

print(min_price)