function Main(input){
    input=input.split("\n");  //ここまで必須
    
  	var num1=input[0].split(" ");
    var num2=input[1].split(" ");
    var num=new Array();
    for (i=0;i<num1[0];i++){
        num.push(num2[i]);
    }
    num.sort(
        function(a,b){
            return(a<b?1:-1);
        }
    )
    var result=0;
    for (j=0;j<num1[1];j++){
        result=result+parseInt(num[j])
    }
  console.log(result);
}

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