(* O((n+m)log(n+m)) *)
open Array
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let a_s = init n @@ fun _ -> Scanf.scanf " %d" @@ fun a -> a, 1
let cbs = init m @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> b, a
let cards = make (n + m) (0, 0)
let rec f acc i r =
  if r <= 0 then acc
  else
    let x, c = cards.(i) in
    f (acc + x * min c r) (i + 1) @@ r - min c r
let _ =
  iteri (fun i a -> cards.(i) <- a) a_s;
  iteri (fun i cb -> cards.(n + i) <- cb) cbs;
  sort (fun x y -> compare y x) cards;
  f 0 0 n |> Printf.printf "%d\n"