<?php

fscanf(STDIN, "%d %d", $a, $b);
$line = fgets(STDIN);
$arr = array_map('intval', explode(' ', $line));
$sum = 0; 
$num = count($arr);

for ($i = 0; $i < $b; $i++) {
  $min = min($arr);
  $min_key = min(array_keys($arr));
  $sum += $min;
  unset($arr[$min_key]);
  $arr = array_values($arr);
  
}

echo $sum;


?>
