import Data.List
import Control.Monad

gen_modifier::[(Int,Int)]->[Int]
gen_modifier ls = let srtd = sortBy (\ (_,c_1) -> \ (_,c_2) -> compare c_2 c_1) ls  in
                  concat [take b (repeat c)|(b,c)<-srtd]


solver::[(Int,Int)]->[Int]->Int
solver bcs a_s =  let sorted_as = sort a_s in
                  let incr =  (sum.takeWhile (0<).map (\ (c,a)-> c-a).zip (gen_modifier bcs)) sorted_as in
                  incr  + (sum a_s)

main::IO()
main=do
  n:m:_ <- return . map read . words =<< getLine
  a_s   <- return . map read . words =<< getLine
  bcs <- forM [1..m] (\ _ -> return . (\ (b:c:_) -> (b,c)) .  map read . words =<< getLine)
  print (solver bcs a_s)