open Scanf
open Printf
(* #load "str.cma" ;; *)

let (n,m) = sscanf (read_line ()) "%d %d" (fun n m -> (n,m));;
let wsp_regex = Str.regexp "[ ]+";;
let words = Str.split wsp_regex (read_line ());;
let intlist = List.sort compare (List.map (fun x -> int_of_string x) words);;
let list_input =
  let rec loop list num =
    match num with 
    0 -> list
    | x -> loop ((sscanf (read_line ()) "%d %d" (fun b c  -> (b,c)))::list) (x-1)
    in loop [] m;;
let query = List.sort (fun x y -> -compare (snd x) (snd y)) list_input;;

(* let () = List.iter (fun x -> printf "%d " x) intlist;;
let () = print_newline();;
let () = List.iter (fun x -> printf "%d %d:" (fst x) (snd x)) query;; *)

let ans () =
  let rec loop lists querys count sum =
    match lists,querys with
    [], _ -> sum
    | l :: list_rest, [] -> loop list_rest querys count (sum+l)
    | l :: list_rest, (b,c) :: query_rest -> 
      if (c > l && b > count) then
        loop list_rest querys (count+1) (sum+c)
      else if (c > l && b <= count) then
        loop lists query_rest 0 (sum)
      else 
        loop list_rest query count (sum+l)
  in loop intlist query 0 0;;

  let () = printf "%d\n" (ans());;