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
    p := a[(l + r) div 2]; 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;
            j := j - 1;
            i := i + 1;
        end;
    end;

    if (l - r > 1) then begin
        qs(l, j);
        qs(i, 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 := sum + a[i];
    

    writeln(sum);
end.