import itertools
N,K = map(int,input().split())
p = [int(m) for m in input().split()]

if K == 1:
    print(*p)

if K == 2:
    p2list = list(itertools.combinations(p, 2))
    print(sum(min(p2list)))
    
if K >= 3:
    p3list = list(itertools.combinations(p, 3))
    print(sum(min(p3list)))