import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,K = mips()
ans = 10**9
P = [p for p in mips()]
L = list(map(list,itertools.permutations(P,K)))
for el in L:
    ans = min(ans,sum(el))
print(ans)
    
