import Data.List
import Control.Monad

main = do
  [n, m] <- map read . words <$> getLine
  as <- map read . words <$> getLine :: IO [Int]
  bc <- map (map read . words) <$> replicateM m getLine :: IO [[Int]]
  print $ sum $ solve bc as

solve bc as =
  foldl f as bc
  where
    f xs [b, c] =
      let (ys, zs) = partition (\x -> x < c) xs
          (yys, zzs) = splitAt b $ sort ys
      in
         replicate (length yys) c ++ zzs ++ zs