# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
arr = []
chlst = []
while l = $stdin.gets do
  if lc == 0
    tmp = l.chomp.split(" ").map(&:to_i)
    nn = tmp[0]
    mm = tmp[1]
  elsif lc == 1
    arr = l.chomp.split(" ").map(&:to_i)
  else
    chlst << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

arr.sort!
chlst.sort_by! do |a, b| b end
chlst.reverse!

# body
if $debugFlag
  p arr
  p chlst
end

ptr = 0
cnt = 0
chlstSize = chlst.size
arr.size.times do |i|
  break if ptr >= chlstSize
  break if (arr[i] >= chlst[ptr][1])
  arr[i] = chlst[ptr][1]
  cnt += 1
  if cnt >= chlst[ptr][0]
    ptr += 1
    cnt = 0
  end
end

puts arr.inject(:+)
