import sys
from io import StringIO
import unittest
from itertools import combinations

def resolve():
	n, k = map(int, input().split())
	seq = map(int, input().split())
	ans = float('inf')
	for r in combinations(seq, k):
		ans = min(ans, sum(r))
	print(ans)
resolve()