function Main(arg) {
    var arg = arg.trim().split('\n');
    let n = Number(arg[0].split(' ')[0]);
    let k = Number(arg[0].split(' ')[1]);
    let p = arg[1].split(' ').sort(
      (a,b) => {
        if(Number(a)<Number(b))return -1;
        if(Number(a)>Number(b))return 1;
        return 0;
      }
    );
    let ans = 0;
    for(i = 0; i < k;i++){
      ans = ans + Number(p[i]);
    }
    console.log(ans);
    return;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
