from itertools import combinations
N, K = map(int, input().split())
P = list(map(int, input().split()))

ans = float('inf')

for buy_list in list(combinations(P, K)):
    ans_ = 0
    for buy in buy_list:
        ans_ += buy
    ans = min(ans, ans_)
    
print(ans)