
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

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

{-
data InsOp = InsOp {pos :: Int, el :: Int, len :: Int} deriving (Eq,Show)

apply :: InsOp -> U.Vector Int -> U.Vector Int
apply x v = 
-}


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 folded
    print $ U.sum folded


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