class MinHeap
  def initialize(arr)
    @heap = []
    arr.each { |e| up_heap(e) }
  end

  def peek
    @heap[1]
  end

  def up_heap(x)
    @heap << nil if @heap == []

    @heap << x
    idx = @heap.size - 1

    while idx != 1
      parent = idx / 2
      break if @heap[idx] > @heap[parent]

      @heap[idx], @heap[parent] = @heap[parent], @heap[idx]
      idx = parent
    end
  end

  def down_heap
    return @heap.pop if @heap.size <= 2

    min = @heap[1]
    @heap[1] = @heap.pop
    idx = 1
    size = @heap.size

    while idx * 2 < size
      l = idx * 2
      r = l + 1

      if @heap[r]
        child = @heap[l] < @heap[r] ? l : r
      else
        child = l
      end

      break if @heap[idx] < @heap[child]

      @heap[idx], @heap[child] = @heap[child], @heap[idx]
      idx = child
    end

    min
  end

  def to_a
    @heap.shift
    @heap
  end

  alias_method :<<, :up_heap
  alias_method :push, :up_heap
  alias_method :shift, :down_heap
end

n, m = gets.split.map(&:to_i)
q = MinHeap.new(gets.split.map(&:to_i))
b, c = Array.new(m) { gets.split.map(&:to_i) }.transpose
count = 0

b.zip(c).sort_by { |x, y| -y }.each do |x, y|
  x.times do
    break if q.peek >= y || count == n

    q.shift
    q << y
    count += 1
  end
end

puts q.to_a.sum