function Main(input) {
    input = input.split("\n");
    
    const numberArray = input[0].split(' ');
    let priceArray = input[1].split(' ');
    const num = Number(numberArray[1]);

    var sum = 0;
    for (let i = 0; i<num; i++) {
        const min = Math.min(...priceArray);
        sum += min;
        var index = priceArray.indexOf(String(min));
        if (index > -1) {
           priceArray.splice(index, 1);
        }
    }
    console.log(sum);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));