n, m = gets.split.map(&:to_i)
cards = gets.split.map(&:to_i).sort
queries = []
m.times { queries << gets.split.map(&:to_i) }
queries.sort! { |a, b| b[1] <=> a[1] }
after_changed = []
(0...n).each do |i|
  if after_changed.empty? && !queries.empty?
    count, changed = queries.shift
    after_changed = [changed] * count
  elsif after_changed.empty? && queries.empty?
    break
  end
  if cards[i] < after_changed[0]
    cards[i] = after_changed.shift
  end
end
puts cards.inject(:+)
