N, M = gets.split.map &:to_i
aaa = gets.split.map(&:to_i).sort
while g = gets&.split&.map(&:to_i)
    aaa << [g[1]] * g[0]
end
aaa.flatten!.sort!
sum = 0
N.times do |i|
  sum += aaa[aaa.size - i - 1]
end
puts sum
