import Control.Monad
import Data.List
main = do
  [n,m] <- map read . words <$> getLine
  as <- map read . words <$> getLine
  bcs <- replicateM m $ map read . words <$> getLine
  let cs = concat [replicate b c | [c,b] <- reverse $ sort $ map reverse bcs]
  print $ sum $ map toInteger $ zipWith max (sort as) (cs ++ repeat 0)