module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let elts = Array.make (n + m) (0, 0) in
  for i = 0 to n - 1 do
    Scanf.scanf "%d " @@ fun a ->
      elts.(i) <- (a, 1)
  done;
  for i = 0 to m - 1 do
    Scanf.scanf "%d %d\n" @@ fun b c ->
      elts.(i + n) <- (c, b)
  done;
  Printf.printf "%d\n" @@ fst @@
  List.fold_left (fun (acc, n) (c, b) ->
    acc + c * min n b, n - min n b) (0, n) @@
  List.rev @@
  IntMap.bindings @@
  Array.fold_left (fun m (c, b) ->
    IntMap.add c (b + try IntMap.find c m with Not_found -> 0) m) IntMap.empty elts