def integer_cards(cards, params)
  card_keys = cards.uniq.sort
  card_count = cards.each_with_object(Hash.new { |h, k| h[k] = 0 }) { |i, h| h[i] += 1 }

  param_keys = []
  param_count = Hash.new { |h, k| h[k] = 0 }
  params.each { |c, k| param_keys << k; param_count[k] += c }
  param_keys.sort_by! { |n| n * -1 }

  param_keys.each do |param_key|
    while ((card_key = card_keys[0]) < param_key) && param_count[param_key] > 0
      replace_count = [card_count[card_key], param_count[param_key]].min
      card_count[card_key] -= replace_count
      param_count[param_key] -= replace_count
      card_count[param_key] += replace_count

      card_keys.shift if card_count[card_key].zero?

      card_keys << param_key
      card_keys.uniq!
      card_keys.sort!
    end
  end

  card_keys.inject(0) { |sum, k| sum + k * card_count[k] }
end

n, m = gets.split.map(&:to_i)
cards = gets.split.map(&:to_i)
params = []
m.times do 
  params << gets.split.map(&:to_i)
end

puts integer_cards(cards, params)