N, K = (int(i) for i in input().split(" "))
p_dict = {c:int(i2) for c, i2 in enumerate(input().split(" "))}
sort_p_list = sorted(p_list.items(), key=lambda x:x[1])
sum=0
for k in range(K):
  sum += sort_p_list[k][1]
print(sum)