program main;
var
    n, k, sum, i: integer;
    a : array[1..1000] of integer;


procedure qs (l, r : integer);
var
    p, i, j, temp : integer;
begin
    if (l < r) then begin    
        p := a[l]; i := l; j := r;
        
        while (i < j) do begin
            while (a[j] >= p) do
                j := j - 1;
            while (a[i] < p) do
                i := i + 1;
            
            if (i < j) then begin
                temp := a[i];
                a[i] := a[j];
                a[j] := temp;
            end;
        end;

        qs(l, i - 1);
        qs(i + 1, r);
    end;
end;


begin
    readln(n, k);

    for i := 1 to n do 
        read(a[i]);

    qs(1, n);

    sum := 0;
    for i := 1 to k do
        sum += a[i];
    

    writeln(sum);
end.