N,K = map(int,input().split(' '))
P = list(map(int,input().spllit(' ')))
if(k==1):
  print(min(P))
else:
  res=[]
  for i in range(K):
    res[i].append(min(P))
    P.remove(min(P))
  print(sum(res)) 