n,k = map(int, input().split())
p = list(map(int, input().split()))
a = []
for i in range(k):
    a.append(1000)

for i in p:
    for j in a:
        if i < j:
            a.append(i)
            a.remove(j)
            p.remove(i)
            break

print(sum(a))
