import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
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

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


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

main :: IO ()
main = do
    [n,m] <- r'
    as <- U.fromListN n . sort <$> r'
    bcs<- U.replicateM m rp
    let folded = U.foldl' (flip solve1) as bcs
    print $ U.sum folded


solve1 :: (Int, Int) -> U.Vector Int -> U.Vector Int
solve1 (b,c) as =
    let (ls,rs) = U.splitAt b as ; x = findBin c as in
    if x > U.length as
        then rs U.++ U.replicate b c
        else if x < U.length ls
            then U.replicate x c U.++ U.drop x as
            else let (lrs,rrs) = U.splitAt (x-b) rs in 
                    lrs U.++ U.replicate b c U.++ rrs


type Range = (Int,Int)

findBin :: Int -> U.Vector Int -> Int
findBin target vec = findBin' target vec (0,U.length vec)

findBin' :: (Ord a, U.Unbox a) => a -> U.Vector a -> Range -> Int
findBin' target vec (l,r)
    | l==r      = l
    | otherwise = let m = med l r in
        if target < vec U.!m
            then findBin' target vec (l,m)
            else findBin' target vec (m+1,r)


med :: Int -> Int -> Int
med a b = div (a+b) 2

