import Data.List

main = do
  li <- getLine
  let [n,m] = map read $ words li
  li <- getLine
  let as = sort $ map read $ words li
  bcs <- getBCs m
  let answer = compute as bcs
  print answer

getBCs 0 = return []
getBCs k = do
  li <- getLine
  let [b,c] = map read $ words li
  bcs <- getBCs (pred k)
  return ((b,c):bcs)

compute as bcs = sum $ loop as bcs

loop as [] = as
loop as ((b,c):bcs) = loop as1 bcs
  where
    x = length $ takeWhile (c >) $ take b as
    as1 = sort (replicate x c ++ drop x as)
