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())

    answer: int = min(tuple(sum(fruits) for fruits in itertools.combinations(p, k)))
    print(answer)


if __name__ == '__main__':
    main()
