if __name__ == "__main__":
    N, K = list(map(int, input().split()))
    p = list(map(int, input().split()))

    print(p)
    p.sort()
    print(p)

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