n, k = input().split()
n = int(n)
k = int(k)
prices = [int(p) for p in input().split()]
min = prices[:k]
for p in prices[k:]:
    for i in range(k):
        if min[i] > p:
            min.append(p)
            min.pop(i)
sum = 0
for p in min:
    sum = sum+p
print(sum)
