N, K = gets.chomp.split(" ").map(&:to_i)
p = gets.chomp.split(" ").map(&:to_i)

q = p.sort
sum = 0
if q[0]
  sum += q[0]
  if q[1]
    sum += q[1]
    if q[2]
      sum += q[2]
    end
  end
end

print sum