from sys import stdin

N, K = map(int, input().split())
prices = list(map(int, input().split()))

prices = sorted(prices)

sum = 0
for i in range(0, K):
    print(prices[i])
    sum += prices[i]
print(sum)