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