N,M = gets.chomp.split.map(&:to_i)
cards = gets.chomp.split.map(&:to_i)

M.times do 
	b,c = gets.chomp.split.map(&:to_i)
	changed = cards.sort!.take(b).map{|a| a = a < c ? c : a}
  	cards = cards.drop(b).unshift(changed).flatten
end

puts cards.inject(:+)