import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C
import Data.Maybe (fromJust)
import Data.List (sort)
import Control.Monad (forM, replicateM)

getInts :: IO [Integer]
getInts = map (fst . fromJust . C.readInteger) <$> C.words <$> B.getLine

rsort :: (Ord a) => [a] -> [a]
rsort = reverse . sort

main :: IO ()
main = do
    [n, m] <- getInts
    xs <- sort <$> getInts
    ys <- rsort <$> replicateM (fromIntegral m) getPair
    print $ sum $ solve xs ys
    where
        getPair = reverse <$> getInts
        solve [] _ = []
        solve xs [] = xs
        solve xs ([_,0]:ys) = solve xs ys
        solve (x:xs) zs@([a,b]:ys)
            | x < a = a : solve xs ([a,b-1]:ys)
            | otherwise = x : solve xs zs