{-# LANGUAGE BangPatterns      #-} --引数に!

import Data.Bits
import Data.Foldable (foldlM,foldrM)
import Data.Maybe (fromJust)
import Data.List
import qualified Data.Vector.Unboxed.Mutable as V
import Control.Monad
import qualified Data.ByteString.Lazy.Char8 as BS
import Debug.Trace

solve :: [(Int,Int)] -> Int -> IO [(Int,Int)]
solve as 0 = return as
solve as m = do
  [b,c] <- map read.words <$> getLine :: IO [Int]
  solve (f as b (b,c)) (m-1)
  where
    f :: [(Int,Int)] -> Int -> (Int,Int) -> [(Int,Int)]
    f as' 0 !(b,c) = (c,b) : as'
    f [] !b' !(b,c) = [(c,b-b')]
    f ((a,cnt):as') !b' !(b,c)
      | c <= a = ((c,b-b'):(a,cnt):as')
      | a < c = if cnt <= b' then f as' (b' - cnt) (b,c)
        else (a,cnt - b') : (f as' 0 (b,c))


initas :: [Int] -> [(Int,Int)]
initas as = sub as 1
  where
    sub [] _ = []
    sub [a] cnt = [(a,cnt)]
    sub (a:b:as') cnt =
      if a == b then sub (b:as') (cnt+1)
        else (a,cnt) : (sub (b:as') 1)

main :: IO ()
main = do
  [n,m] <- map read.words <$> getLine :: IO [Int]
  as <- sort.map read.words <$> getLine :: IO [Int]
  let as' = initas as
  ans <- solve as' m
  print $ foldl' (\x (a,cnt) -> x+(a*cnt)) 0 ans
