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

0.step(m - 1) do |i|
  k = gets.chomp.split.map(&:to_i)
  index = a.bsearch_index {|aa| aa >= k[1]} || n
  next if index == 0
  a = a.insert(index, *Array.new(index < k[0] ? index : k[0]){ k[1] })[k[0], n - 1 + k[0]]
end

p a.inject(:+)