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

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 = List.fold_left (fun map v ->
            M.add v (1 + try M.find v map with _ -> 0) map) M.empty (split (read_line ()))
        in
        let rec loop i map =
            if i = 0 then map else
                let b, c = Scanf.sscanf (read_line ()) "%d %d" (fun b c -> b, c) in
                let rec loop2 rest acc l =
                    match l with
                    | [] -> acc
                    | (k, v) :: tl ->
                        if rest = 0 || k >= c then List.rev_append l acc else
                        if rest >= v then loop2 (rest - v) ((c, v) :: acc) tl else
                            loop2 0 ((k, v - rest) :: (c, rest) :: acc) tl
                in
                let l = M.bindings map in
                let l = loop2 b [] l in
                let a = List.fold_left (fun map (k, v) ->
                    M.add k (v + try M.find k map with _ -> 0) map) M.empty l
                in
                loop (i - 1) a
        in
        let a = loop m a in
        Printf.printf "%d\n" (M.fold (fun k v acc -> k * v + acc) a 0)
    in
    main ()