n,k = input().split()
a = list()
a = input().split(" ")
a.sort()
#while i<int(k): 
 #   print(a[i])
  #  i-=1
k = int(k)
i = 0
sum = 0
while i<k:
    print(int(a[i]))
    sum+=int(a[i])
    i+=1
    
print(sum)