@n,m = gets.split.map(&:to_i)
@cards = gets.split.map(&:to_i)
@raptor = []
@saurus = []

m.times do
b,c = gets.split.map(&:to_i)
@raptor << b
@saurus << c
end

@empty = []

def ope(x)
  for i in 0..(@n - 1)
    if @cards[i] < @saurus[x]
      @empty << @cards[i]
    end
  end


  if @empty.size > @raptor[x]
    @empty.sort!
    @empty.slice!((@raptor[x])..(@empty.size))
    @empty.each do |j|
    @cards[@cards.find_index{|z| z==j}] = @saurus[x]
    end
  else
    @empty.each do |j|
    @cards[@cards.find_index{|z| z==j}] = @saurus[x]
    end
  end

end

for k in 0..m-1
  ope(k)
  @empty  = []
  p @cards
end

puts @cards.sum