using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
class Project
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int K = int.Parse(input[1]);
        int[] A = Console.ReadLine().Split(' ').Select(s => Int32.Parse(s)).ToArray();
        int min = 0;
        int count = 0;
        int Ans = 0;
        while (count < K)
        {
            count++;
            for (int i = 0; i < N; i++)
            {
                if (min == 0 || A[i] <= min)
                {
                    min = A[i];
                }
            }

            for (int j = 0; j < N; j++)
            {
                if (A[j] == min)
                {
                    A[j] = 0;
                    break;
                }
                else
                {
                    continue;
                }
            }
            Ans += min;
            min = 0;
        }
        Console.WriteLine(Ans);
    }
}