using System;

class Program
{
    static void Main(string[] args)
    {
        string[] number = Console.ReadLine().Split(' ');

        int N = int.Parse(number[0]);
        int K = int.Parse(number[1]);

        int[] lowCost = new int[K];

        string[] cost = Console.ReadLine().Split(' ');

        for (int count2 = 0; count2 < K; count2++)
        {
            lowCost[count2]=2000;
        }
        for (int count = 0; count < N; count++)
        {
            for (int count2 = 0; count2 < K; count2++)
            {
                if (lowCost[count2] > int.Parse(cost[count]))
                {
                    lowCost[count2] = int.Parse(cost[count]);
                    break;
                }
            }
        }

        int sum = 0;

        for (int count2 = 0; count2 < K; count2++)
        {
            sum += lowCost[count2];
        }

        Console.WriteLine(sum);
    }
}
