import itertools
import sys
from typing import Callable, NoReturn, Tuple


def main() -> NoReturn:
    readline: Callable[[], str] = sys.stdin.readline
    n, k = map(int, readline().rstrip().split())  # type: int,...
    p: Tuple[int] = tuple(int(_) for _ in readline().rstrip().split())

    if k < n // 2:
        answer: int = 10 ** 6
        for combinations in itertools.combinations(p, k):
            sum_of_comb: int = sum(combinations)
            if sum_of_comb < answer:
                answer = sum_of_comb
    else:
        not_chosen: int = 0
        for combinations in itertools.combinations(p, n - k):
            sum_of_comb: int = sum(combinations)
            if sum_of_comb > not_chosen:
                not_chosen = sum_of_comb
        answer: int = sum(p) - not_chosen

    print(answer)


if __name__ == '__main__':
    main()
