N,K = map(int,input().split())
list = map(int,input().split())
MIN = list[0]
SUM = 0
for j in range(1,K):
  for i in list:
    if MIN > list[i]:
      MIN = list[i]
  list.delete(MIN)
  SUM += MIN
  MIN = list[0]
print(SUM)