function Main(input) {
	var tmp = input.split("\n");
	
	var num = tmp[0].split(" ");
	var price = tmp[1].split(" ");
	var newprice = [];
	var total = 0;
	
	for(var i=0; i<num[0]; i++){
	    newprice.push(parseInt(price[i]));
	}
	
	newprice.sort(
	    function(a,b){
	        if(a>b){
	            return 1;
	        }else if(a<b){
	            return -1;
	        }else{
	            return 0;
	        }
	    }
	);

	for(var n=0; n<num[1]; n++){
	    total+=newprice[n];
	}
	
	console.log(total);
}

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