module Main where

import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust, mapMaybe)
import Control.Monad (replicateM, forM_, foldM)
import qualified Data.Vector.Mutable as MV
import Data.List (sortOn)
import Debug.Trace

readTuple2 :: IO (Int, Int)
readTuple2 = do
    [x, y] <- readInts
    pure (x, y)

readInts :: IO [Int]
readInts = do
    is <- BC.words <$> BC.getLine
    pure $ fst <$> mapMaybe BC.readInt is

main = do
    (n, m) <- readTuple2
    as <- readInts
    let ats = zip (repeat 1) as
    bcs <- replicateM m readTuple2
    let cards = sortOn (((negate 1)*) . snd) $ ats <> bcs
    let acc = (n, 0) -- rem cards, point
    print $ snd $ foldl (\(acc_num, acc_point) (c_num, c_point) ->
        if acc_num < c_num then
            (0, acc_point + acc_num * c_point)
        else
            (acc_num - c_num, acc_point + c_num * c_point)
         ) acc cards