N, M = gets.split.map(&:to_i)
As = gets.split.map(&:to_i)
BCs = readlines.map{|l| l.split.map(&:to_i)}

as = As.sort
ans = 0
BCs.sort_by(&:last).reverse.each do |b, c|
  i = as.bsearch_index{|a| a > c}
  if i
    as, bs = as[0 ... i], as[i .. -1]
    ans += bs.inject(:+)
  end
  break if as.empty?
  j = [as.size, b].min
  as = as[j .. -1] + [c] * j
end
ans += as.inject(:+) unless as.empty?
puts ans