import qualified Data.IntMap as M

main = do
  li <- getLine
  let [n,m] = map read $ words li
  li <- getLine
  let as = map read $ words li
  co <- getContents
  let bcs = map readbc $ lines co
  let ans = compute n m as bcs
  print ans

readbc :: String -> (Int,Int)
readbc s = let [b,c] = map read $ words s in (b,c)

{-
なるべく全体を大きくしたいのだから、
asのうち、なるべく小さいものでci未満のものを、ciに書き換える。を繰り返す。
-}

compute :: Int -> Int -> [Int] -> [(Int,Int)] -> Int
compute n m as bcs = sum $ map (uncurry (*)) $ M.assocs amm
  where
    am0 = M.fromListWith (+) [ (a,1) | a <-as ]
    amm = foldl step am0 bcs
    step am (b,c) -- b個までc円に書き換え可能
      | c <= k = am -- 書き換えると安くなるので打ち切り
      | True = case compare a b of
        GT -> M.insertWith (+) c b $ M.insertWith (+) k (a-b) am1 -- 余った
        EQ -> M.insertWith (+) c b am1 -- ちょうど足りた
        LT -> step (M.insertWith (+) c a am1) (b-a, c)
      where
        ((k,a),am1) = M.deleteFindMin am -- k円のものはa個
