<?php
  
  $a = explode(" ",fgets(STDIN));
  $b = explode(" ",fgets(STDIN));

  sort($b);

  echo calculate($a,$b);

  function calculate($a,$b){
    
     $total = 0;
    
    if($a[1] == 0){
    	return 0; 
    }
    
    if($a[1] == 1){
    	return $b[0]; 
    }

    for($i=0; $i < $a[1]; $i++){
      $total += $b[$i];
    }

    return $total;
  }
