n,k=map(int,input().split())
l1=list(map(int.input().split()))
l1.sort()
price = 0
count= 0
for i in range(n-1):
  if count=k:
      break
  else:    
     if l1[i]!=l1[i+1]:
          price+=l1[i]
          count+=1
print(price)    