a,b = input().split()
c = list(map(int,input().split()))
c.sort
d = [0]*b
e = 0

for i in range(len(c)):
  for k in range(len(b)):
    if c[i] > c[i-1] :
      d[k] = c[i]
      
for j in range(len(b)):
  e += d[j]
  
print(str(e))