[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let [N;M] = reads int
    let AS = reads int64 |> List.sort
    let BCS =
        List.init M (fun _ -> reads int64)
        |> List.sortByDescending (List.item 1)

    let rec solve acc xs = function
        | [] -> acc + List.sum xs
        | [b;c] :: ys ->
            let rec loop acc' b' = function
                | [] -> (acc', [])
                | z :: zs ->
                    if b' = 0L then
                        (acc', z :: zs)
                    elif z < c then
                        loop (acc' + c) (b' - 1L) zs
                    else
                        loop (acc' + z) b' zs
            let acc', xs' = loop acc b xs
            solve acc' xs' ys

    solve 0L AS BCS
    |> printfn "%i"

    0