--editorial
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Data.Ord

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 <- sort <$> r'
    bcs<- sortBy (flip $ comparing snd) <$> replicateM m rp
    let bcsx = concat (map (uncurry replicate) bcs) ++ repeat 0
    print $ sum (zipWith max bcsx as)