let main = (input) => {
    let kind = 0
    let chose = 0
    let usrInput = input.split(/\n/)
    kind = parseInt(usrInput[0].split(/\s+/)[0])
    chose = parseInt(usrInput[0].split(/\s+/)[1])
    let price = usrInput[1].split(/\s+/)
    let priceInt = []
    price.forEach(element => {
        priceInt.push(+element)
    });

    let sum = 0
    for (let index = 0; index < chose; index++) {
        let minus = 0
        for (let jake = 0; jake < priceInt.length; jake++) {
            if(priceInt[minus]>priceInt[jake])
                minus = jake
        }
        sum+=priceInt[minus]
        priceInt.splice(minus,1)
    }

    console.log(sum)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))