import Control.Monad
import Data.List
import Data.Ord

main = do
  [n, m] <- map read . words <$> getLine
  cards <- map read . words <$> getLine
  reads <- replicateM m $ map read . words <$> getLine
  let cs = sort cards
  let xs = sortBy (comparing Down) (sort' $ concat reads)
  print $ sum $ func xs cs

sort' :: [Int] -> [Int]
sort' [] = []
sort' (a:b:xs) = replicate a b ++ sort' xs

func :: [Int] -> [Int] -> [Int]
func xs = zipWith max (xs ++ repeat 0)
