import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import Data.List (sortBy)
import Data.Tuple (swap)
import Data.Function (on)

main :: IO ()
main = do
  let
    f :: Int -> [(Int, Int)] -> Int
    f = go 0
      where
        go :: Int -> Int -> [(Int, Int)] -> Int
        go s k ((i, j) : rest) | j < k     = go (s + i * j) (k - j) rest
                               | otherwise = s + i * k
        go s _ _                           = s
  [n, m] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    as' = map (flip (,) 1) $ as :: [(Int, Int)]
  bcs <- map (unsafeListToPair . map unsafeTextToInt . T.words) . T.lines <$> T.getContents :: IO [(Int, Int)]
  let
    cbs = map swap $ bcs :: [(Int, Int)]
  print . f n . sortBy (flip compare `on` fst) $ cbs ++ as'

unsafeListToPair :: [Int] -> (Int, Int)
unsafeListToPair [x, y] = (x, y)
{-# INLINE unsafeListToPair #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}
