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

