import Control.Monad
import Data.List

main=do
  [n,m]<-map read.words<$>getLine
  as<-map read.words<$>getLine
  bcs<-replicateM m$(\[a,b]->(a,b)).map read.words<$>getLine
  print $ solve as bcs

solve :: [Integer]->[(Integer,Integer)]->Integer
solve as bcs = go sas sbcs
  where
  go [] _ = 0
  go as [] = sum as
  go (a:as) ((b,c):bcs)
    | b == 0 = go (a:as) bcs
    | c > a = c + go as ((b-1,c):bcs)
    | otherwise = a + go as ((b,c):bcs)
  sas = sort as
  sbcs = sortBy f bcs
  f (_,a) (_,b) = compare b a