import Control.Monad
import Data.List
f an sp n=if (null sp)||(n>=head(head sp)) then sum(an) else let p=head(head sp);q=last(head sp) in f ((map(\x->if q>x then q else x)(take p an))++(drop p an)) (drop 1 sp) p
main=do
 [n,m]<-map read.words<$>getLine
 an<-map read.words<$>getLine
 bc<-replicateM m (map read.words<$>getLine)
 let sp=sortBy(\x y->let p=last x;q=last y in if p>q then LT else if p==q then EQ else GT)bc
     sa=sort an
 print$f sa sq
 