def resolve():
    import itertools
    N, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    minA = 10**9
    for a in itertools.combinations(A, K):
        minA = min(minA, sum(a))
    print(minA)

resolve()
