lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end
a = lines[0]
b = lines[1]

arr = []

a[1].times {
  arr.push(b.min)
  b.delete_at(arr.find_index(b.min))
}

puts arr.sum