total = 0
_, m = gets.chomp.split.map(&:to_i)
h = Hash.new(0)
gets.chomp.split.each do |a|
  a = a.to_i
  h[a] += 1
  total += a
end
x = Hash.new(0)
m.times do
  b, c = gets.chomp.split.map(&:to_i)
  x[c] += b
end
y = x.keys.sort.reverse
y.each do |c|
  b = x[c]
  keys = h.keys.select { _1 < c }
  keys.sort.each do |k|
    v = h[k]
    next if v.zero?

    if v > b
      h[k] -= b
      h[c] += b
      total += (c - k) * b
      b = 0
    else
      h[k] -= v
      h[c] += v
      total += (c - k) * v
      b -= v
    end
    break if b.zero?
  end
end

puts total
