import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

n, k = map(int, input().split())
P = list(map(int, input().split()))

from itertools import combinations

ans = 10 ** 12
for i in combinations(P, k):
    ans = min(ans, sum(i))
print(ans)
