n, m = gets.split.map(&:to_i)
cards = gets.split.map(&:to_i).sort
replace = m.times.map{|i| gets.split.map(&:to_i)}.sort_by{|count, value| value}
replace.size.times.reverse_each.drop(1).each{|i| replace[i][0] += replace[i + 1][0]}
replace.unshift([n, 0])

sum = 0
current_rep = replace.pop
cards.each_with_index{|value, index|
    if index + 1 > current_rep[0]
        current_rep = replace.pop
    end
    sum += [value, current_rep[1]].max
}
puts sum
