from collections import deque
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
B = [0]*M
dic = {}
for i in range(M):
    c,b = list(map(int,input().split()))
    B[i] = b
    if dic.get(b):dic[b] += c
    else:dic[b] = c
# print(dic)
A = deque(sorted(A))
B = deque(sorted(list(set(B)),reverse=True))
C = []

while A:
    b = B[0]
    if A[0]<b:
        A.popleft()
        C.append(b)
        dic[b] -= 1
        if dic[b]==0:
            B.popleft()
            if not B:break
    else:break
# print(dic[C[0]])
print(sum(A)+sum(C)) from collections import deque N,M = list(map(int,input().split())) N list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split M A = list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split B = [0]*M B [0]*M [0] 0 M dic = {} dic {} for i in range(M):
    c,b = list(map(int,input().split()))
    B[i] = b
    if dic.get(b):dic[b] += c
    else:dic[b] = c
# print(dic) i range(M) range M c,b = list(map(int,input().split())) c list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split b B[i] = b B[i] B i b if dic.get(b):dic[b] += c
    else:dic[b] = c
# print(dic) dic.get(b) dic.get dic get b A = deque(sorted(A)) A deque(sorted(A)) deque sorted(A) sorted A B = deque(sorted(list(set(B)),reverse=True)) B deque(sorted(list(set(B)),reverse=True)) deque sorted(list(set(B)),reverse=True) sorted list(set(B)) list set(B) set B reverse=True reverse True C = [] C [] while A:
    b = B[0]
    if A[0]<b:
        A.popleft()
        C.append(b)
        dic[b] -= 1
        if dic[b]==0:
            B.popleft()
            if not B:break
    else:break
# print(dic[C[0]]) A b = B[0] b B[0] B 0 if A[0]<b:
        A.popleft()
        C.append(b)
        dic[b] -= 1
        if dic[b]==0:
            B.popleft()
            if not B:break
    else:break
# print(dic[C[0]]) A[0]<b A[0] A 0 b A.popleft() A.popleft A popleft C.append(b) C.append C append b dic[b] -= 1 dic[b] dic b 1 if dic[b]==0:
            B.popleft()
            if not B:break
     dic[b]==0 dic[b] dic b 0 B.popleft() B.popleft B popleft if not B:break
     not B B print(sum(A)+sum(C)) print sum(A)+sum(C) sum(A) sum A sum(C) sum C dic = {} {} dic A = deque(sorted(A)) deque(sorted(A)) A b = list(map(int,input().split())) list(map(int,input().split())) b M = list(map(int,input().split())) list(map(int,input().split())) M B = [0]*M [0]*M B B = deque(sorted(list(set(B)),reverse=True)) deque(sorted(list(set(B)),reverse=True)) B c,b = list(map(int,input().split())) list(map(int,input().split())) c b = B[0] B[0] b N,M = list(map(int,input().split())) list(map(int,input().split())) N A = list(map(int,input().split())) list(map(int,input().split())) A C = [] [] C
from collections import deque
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
B = [0]*M
dic = {}
for i in range(M):
    c,b = list(map(int,input().split()))
    B[i] = b
    if dic.get(b):dic[b] += c
    else:dic[b] = c
# print(dic)
A = deque(sorted(A))
B = deque(sorted(list(set(B)),reverse=True))
C = []

while A:
    b = B[0]
    if A[0]<b:
        A.popleft()
        C.append(b)
        dic[b] -= 1
        if dic[b]==0:
            B.popleft()
            if not B:break
    else:break
# print(dic[C[0]])
print(sum(A)+sum(C))