let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then (
                if flag then cur :: acc else acc
            ) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) 0 false (cur :: acc)
                | false, ' ' -> loop (i + 1) 0 false acc
                | true,  v   -> loop (i + 1) (cur * 10 + int_of_char v - 48) true acc
                | false, v   -> loop (i + 1) (cur * 10 + int_of_char v - 48) true acc
            )
        in
        List.rev (loop 0 0 false [])
    in
    let main () =
        let n, m = Scanf.sscanf (read_line ()) "%d %d" (fun n m -> n, m) in
        let a = Array.of_list (split (read_line ())) in
        Array.sort compare a;
        let bc = Array.init m
            (fun _ -> Scanf.sscanf (read_line ()) "%d %d" (fun b c -> c, b))
        in
        Array.sort (fun a b -> compare b a) bc;
        let cur = ref 0 in
        for i = 0 to m - 1 do
            let (c, b) = bc.(i) in
            for j = i to min (n - 1) (i + b - 1) do
                if !cur < n then a.(!cur) <- max a.(!cur) c;
                cur := !cur + 1
            done
        done;
        Printf.printf "%d\n" (Array.fold_left (+) 0 a)
    in
    main ()