from itertools import combinations

N, K = [int(x) for x in input().split()]
prices = [int(x) for x in input().split()]

min_value = 1000 * 1000
for x in combinations(prices, K):
  min_value = min(min_value, sum(x))

print(min_value)