N,M=gets.chomp.split(" ").map(&:to_i)
array=gets.chomp.split(" ").map(&:to_i).sort
bcs=[]
M.times do
    b,c=gets.chomp.split(" ").map(&:to_i)
    bcs.push([b,c])
end
bcs=bcs.sort_by{|b,c|c}
bcs.each do |b,c|
    index=array.bsearch_index {|x| x>=c} || N
    num = b < index ? b : index
    (0..(num-1)).each do |n|
        array[n] = c
    end
    while num < N && array[num] < c do
        a = array[num]
        array.delete_at(num)
        array.insert(0, a)
        num+=1
    end
end
puts array.inject(:+)
