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 =
  f (sort as) (reverse (sortOn (\[_, x] -> x) bc))
  where
    f [] _ = []
    f xs [] = xs
    f xs ([0, _]:ys) = f xs ys
    f (x:xs) zs@([a, b]:ys)
        | x < b = b : f xs ([a-1, b]:ys)
        | otherwise = x : f xs zs