import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m = i_map()
    a_list = i_list()
    num_list = i_row_list(m)

    a_list.sort(reverse=True)
    num_list = sorted(num_list, key=lambda x: -x[1])

    ans = 0
    a_count = 0
    num_count = 0
    for _ in range(n):
        if num_count == m or a_list[a_count] > num_list[num_count][1]:
            ans += a_list[a_count]
            a_count += 1
        else:
            ans += num_list[num_count][1]
            num_list[num_count][0] -= 1
            if num_list[num_count][0] == 0:
                num_count += 1
    print(ans)

if __name__ == '__main__':
    main() import sys, re sys re from math import ceil, floor, sqrt, pi, factorial, gcd from copy import deepcopy from collections import Counter, deque from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left, bisect_right from functools import reduce from decimal import Decimal, getcontext def i_input(): return int(input()) i_input def i_map(): return map(int, input().split()) i_map def i_list(): return list(i_map()) i_list i_input() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) i_input() i_input def i_row(N): return [i_input() for _ in range(N)] i_row N N i_list() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) i_list() i_list def i_row_list(N): return [i_list() for _ in range(N)] i_row_list N N def s_input(): return input() s_input def s_map(): return input().split() s_map def s_list(): return list(s_map()) s_list s_input for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) s_input def s_row(N): return [s_input for _ in range(N)] s_row N N s_list() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) s_list() s_list def s_row_list(N): return [s_list() for _ in range(N)] s_row_list N N def lcm(a, b): return a * b // gcd(a, b) lcm a a b b sys.setrecursionlimit(10 ** 6) sys.setrecursionlimit sys setrecursionlimit 10 ** 6 10 6 INF = float('inf') INF float('inf') float 'inf' MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 num_list = [] num_list [] str_list = [] str_list [] def main():
    n, m = i_map()
    a_list = i_list()
    num_list = i_row_list(m)

    a_list.sort(reverse=True)
    num_list = sorted(num_list, key=lambda x: -x[1])

    ans = 0
    a_count = 0
    num_count = 0
    for _ in range(n):
        if num_count == m or a_list[a_count] > num_list[num_count][1]:
            ans += a_list[a_count]
            a_count += 1
        else:
            ans += num_list[num_count][1]
            num_list[num_count][0] -= 1
            if num_list[num_count][0] == 0:
                num_count += 1
    print(ans) main n, m = i_map() n i_map() i_map m a_list = i_list() a_list i_list() i_list num_list = i_row_list(m) num_list i_row_list(m) i_row_list m a_list.sort(reverse=True) a_list.sort a_list sort reverse=True reverse True num_list = sorted(num_list, key=lambda x: -x[1]) num_list sorted(num_list, key=lambda x: -x[1]) sorted num_list key=lambda x: -x[1] key lambda x: -x[1] -x[1] x[1] x 1 x ans = 0 ans 0 a_count = 0 a_count 0 num_count = 0 num_count 0 for _ in range(n):
        if num_count == m or a_list[a_count] > num_list[num_count][1]:
            ans += a_list[a_count]
            a_count += 1
        else:
            ans += num_list[num_count][1]
            num_list[num_count][0] -= 1
            if num_list[num_count][0] == 0:
                num_count += 1
     _ range(n) range n if num_count == m or a_list[a_count] > num_list[num_count][1]:
            ans += a_list[a_count]
            a_count += 1
        else:
            ans += num_list[num_count][1]
            num_list[num_count][0] -= 1
            if num_list[num_count][0] == 0:
                num_count += 1
     num_count == m or a_list[a_count] > num_list[num_count][1] num_count == m num_count m a_list[a_count] > num_list[num_count][1] a_list[a_count] a_list a_count num_list[num_count][1] [num_count] num_list num_count 1 ans += a_list[a_count] ans a_list[a_count] a_list a_count a_count += 1 a_count 1 ans += num_list[num_count][1] ans num_list[num_count][1] [num_count] num_list num_count 1 num_list[num_count][0] -= 1 num_list[num_count][0] [num_count] num_list num_count 0 1 if num_list[num_count][0] == 0:
                num_count += 1
     num_list[num_count][0] == 0 num_list[num_count][0] [num_count] num_list num_count 0 0 num_count += 1 num_count 1 print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main num_list = [] [] num_list def i_row(N): return [i_input() for _ in range(N)] def i_row(N): return [i_input() for _ in range(N)] i_row def i_map(): return map(int, input().split()) def i_map(): return map(int, input().split()) i_map def i_list(): return list(i_map()) def i_list(): return list(i_map()) i_list MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD def s_row(N): return [s_input for _ in range(N)] def s_row(N): return [s_input for _ in range(N)] s_row str_list = [] [] str_list def i_input(): return int(input()) def i_input(): return int(input()) i_input def s_map(): return input().split() def s_map(): return input().split() s_map def lcm(a, b): return a * b // gcd(a, b) def lcm(a, b): return a * b // gcd(a, b) lcm def main():
    n, m = i_map()
    a_list = i_list()
    num_list = i_row_list(m)

    a_list.sort(reverse=True)
    num_list = sorted(num_list, key=lambda x: -x[1])

    ans = 0
    a_count = 0
    num_count = 0
    for _ in range(n):
        if num_count == m or a_list[a_count] > num_list[num_count][1]:
            ans += a_list[a_count]
            a_count += 1
        else:
            ans += num_list[num_count][1]
            num_list[num_count][0] -= 1
            if num_list[num_count][0] == 0:
                num_count += 1
    print(ans) def main():
    n, m = i_map()
    a_list = i_list()
    num_list = i_row_list(m)

    a_list.sort(reverse=True)
    num_list = sorted(num_list, key=lambda x: -x[1])

    ans = 0
    a_count = 0
    num_count = 0
    for _ in range(n):
        if num_count == m or a_list[a_count] > num_list[num_count][1]:
            ans += a_list[a_count]
            a_count += 1
        else:
            ans += num_list[num_count][1]
            num_list[num_count][0] -= 1
            if num_list[num_count][0] == 0:
                num_count += 1
    print(ans) main def s_list(): return list(s_map()) def s_list(): return list(s_map()) s_list def i_row_list(N): return [i_list() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] i_row_list def s_input(): return input() def s_input(): return input() s_input INF = float('inf') float('inf') INF def s_row_list(N): return [s_list() for _ in range(N)] def s_row_list(N): return [s_list() for _ in range(N)] s_row_list
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, m = i_map()
    a_list = i_list()
    num_list = i_row_list(m)

    a_list.sort(reverse=True)
    num_list = sorted(num_list, key=lambda x: -x[1])

    ans = 0
    a_count = 0
    num_count = 0
    for _ in range(n):
        if num_count == m or a_list[a_count] > num_list[num_count][1]:
            ans += a_list[a_count]
            a_count += 1
        else:
            ans += num_list[num_count][1]
            num_list[num_count][0] -= 1
            if num_list[num_count][0] == 0:
                num_count += 1
    print(ans)

if __name__ == '__main__':
    main()
