N,K= map(int,input())

A = list(map(int,input().split()))

B = [1001 fo i in range(K)]

for x in A:
  for i in range(K):
    if x < B[i]:
      B[i] = x
      break

S = 0
for y in B:
  S += y
print(S)