n, m = gets.split.map(&:to_i)
a_n = gets.split.map(&:to_i).sort!
b_m = []
c_m = []
m.times do |i|
  b, c = gets.split.map(&:to_i)
  b_m << b
  c_m << c
end

sorted_index = 0
m.times do |i|
  p a_n
  b = b_m[i]
  c = c_m[i]
  (b).times do |j|

    if c > a_n[sorted_index]
      a_n[sorted_index] = c
      sorted_index += 1
      next
    end

    a_n.sort!
    sorted_index = 0

    if c > a_n[sorted_index]
      a_n[sorted_index] = c
      sorted_index += 1
      next
    end
  end

end

puts a_n.inject(&:+)