n, m = gets.split.map(&:to_i)                                                                                                                                                                                                                                              
a = gets.split.map(&:to_i).sort

k = m.times.flat_map do
  b, c = gets.split.map(&:to_i)
  [c] * b
end
k = k.sort.reverse

s = 0
a.size.times do |i|
  s += [a[i],k[i]].compact.max
end

puts s