n, m = gets.chomp.split(" ")
m = m.to_i
cards = gets.chomp.split(" ")
cards.map!(&:to_i).sort!
b_c = []
m.times do
  b, c = gets.chomp.split(" ")
  b_c.push([b.to_i, c.to_i])
end


for b, c in b_c
  l, r = cards.partition{|index| index < c}
  tmp = l.shift(b)
  tmp.fill(c)
  cards = l + r + tmp
  cards.sort!
end
  puts cards.inject(:+)