N, M = gets.split.map(&:to_i)
As = gets.split.map(&:to_i)
BCs = readlines.map{|l| l.split.map(&:to_i)}

puts (As.map{|a| [1, a]} + BCs).sort_by{|b, c| -c}.lazy.flat_map{|b, c| [c] * b}.take(N).inject(:+)