n, m = gets.split.map(&:to_i)
as = gets.split.map(&:to_i).sort
bc = m.times.map {gets.split.map(&:to_i)}.sort_by {|b, c| -c}

e = Enumerator.new {|y|
  bc.each do |b, c|
    b.times {y << c}
  end
  loop {y << 0}
}

result = 0
as.each do |a|
  nxt = e.next
  result += a < nxt ? nxt : a
end

puts result