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
        for i = 1 to m do
            Array.sort compare a;
            let b, c = Scanf.sscanf (read_line ()) "%d %d" (fun b c -> b, c) in
            let rec fill i =
                if i < b && a.(i) < c then (
                    a.(i) <- c;
                    fill (i + 1)
                )
            in
            fill 0
        done;
        Printf.printf "%d\n" (Array.fold_left (+) 0 a)
    in
    main ()
