N,K= map(int,input().split())
 
A = list(map(int,input().split()))
 
B = [1001 for 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)