using System;

namespace ABC171B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, k;
            var aa = Console.ReadLine().Split(" ");
            n = int.Parse(aa[0]);
            k = int.Parse(aa[1]);
            int x = 0;
            int[] a = new int[n ];
            var ac = Console.ReadLine().Split(" ");
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(ac[i]);

            Array.Sort(a,(e,b) => e-b);

            for (int i = 0; i < k; i++)
            {
                Console.WriteLine(a[i]);
                x += a[i];
            }
            Console.WriteLine(x);

        }
    }
}
