
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


toTup [a,b] = (a,b)


main :: IO ()
main = do
    [n,m] <- r'
    as <- sort <$> r'
    bcs<- map toTup . reverse <$> replicateM m r'
    let folded = foldr solve1 as bcs
    -- print folded
    print $ sum folded


solve1 :: (Int, Int) -> [Int] -> [Int]
solve1 (b,c) as = -- traceShow as $
    let (ls,rs) = splitAt b as in
    case findIndex (c <) as of
        Nothing -> rs ++ replicate b c
        Just x -> if x < length ls
            then replicate x c ++ drop x as -- drop x ls ++ as
            else let (lrs,rrs) = splitAt (x-b) rs in 
                    lrs ++ replicate b c ++ rrs

{-}
insert' :: (Int,Int) -> [Int] -> [Int]
insert' (len,elm) ls =
    let findIndex (elm <) ls of
        Nothing -> replicate len elm
-}