(* O(N log N (N = max n m)) *)
Scanf.scanf "%d %d" @@ fun n m ->
  let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0 in
  let bcs = Array.init m @@ fun _ -> Scanf.scanf " %d %d" @@ fun b c -> b, c in
  let cmp (a, c) (a1, c1) = c1 - c in
  Array.sort (-) a_s;
  Array.sort cmp bcs;
  let show_ans () = Printf.printf "%d\n" @@ Array.fold_left (+) 0 a_s in
  let k = ref 0 in
  for j = 0 to m - 1 do
    let a, c = bcs.(j) in
    let changed = ref false in
    for i = !k to min (n - 1) @@ !k + a - 1 do
        if a_s.(i) <= c then (a_s.(i) <- c; k := i + 1; changed := true)
    done;
    if not !changed then (show_ans (); exit 0)
  done;
  show_ans ()