n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
bc = []
m.times do
  bc.push gets.split.map(&:to_i)
end

class Heap
  def initialize(n)
    @heap = Array.new(n) { 0 }
    @sz = 0
  end

  def push(x)
    i = @sz
    @sz += 1
    while i > 0
      p = (i - 1) / 2
      break if @heap[p] <= x

      @heap[i] = @heap[p]
      i = p
    end
    @heap[i] = x
  end

  def pop
    ret = @heap[0]
    @sz -= 1
    x = @heap[@sz]
    i = 0
    while i * 2 + 1 < @sz
      a = i * 2 + 1
      b = i * 2 + 2
      a = b if b < @sz && @heap[b] < @heap[a]

      break if @heap[a] >= x

      @heap[i] = @heap[a]
      i = a
    end
    @heap[i] = x
    ret
  end

  def top
    @heap[0]
  end
end

heap = Heap.new(n)
a.each do |e|
  heap.push e
end
bc.each do |e|
  b = e.first
  c = e.last
  b.times do
    x = heap.top
    if x >= c
      break
    end
    heap.pop
    heap.push c
  end
end
sum = 0
n.times do
  sum += heap.pop
end
puts sum
