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 =
  take (length as) $ concatMap (\(x, y) -> replicate x y) xs
  where
    xs =
      reverse $ sortOn snd $ map (\[x, y] -> (x, y)) bc ++ map (\a -> (1, a)) as