n, m = gets.chomp.split(' ').map(&:to_i)
as = gets.chomp.split(' ').map(&:to_i)
bcs = m.times.map { gets.chomp.split(' ').map(&:to_i) }

nums = as + bcs.map { |b, c| [c] * b }.reduce(:+)
nums = nums.sort.reverse

p nums[(0...n)].reduce(:+)
