import Control.Monad
import Data.List
main = do
  [n,m] <- map read . words <$> getLine
  as <- sort . map read . words <$> getLine
  bcs <- fmap (reverse . sortOn snd) . replicateM m $ do
    [b,c] <- map read . words <$> getLine
    return (b,c)
  print $ f as bcs

f [] _  = 0
f as [] = sum as
f as ((0,_):bcs) = f as bcs
f (a:as) ((b,c):bcs) 
  | a > c     = sum (a:as)
  | otherwise = c + f as ((b-1,c):bcs)