from collections import deque
N,M = map(int,input().split())
A = list(map(int,input().split()))
bc = [tuple(map(int,input().split())) for _ in range(M)]
for x in A:
    bc.append((1,x))
bc.sort(key=lambda x:x[1], reverse=True)
A = []
for b,c in bc:
    while len(A) < N and b > 0:
        b -= 1
        A.append(c)
    if len(A) == N:
        break
A.sort(reverse=True)
print(sum(A)) from collections import deque N,M = map(int,input().split()) N 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 tuple(map(int,input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split bc = [tuple(map(int,input().split())) for _ in range(M)] bc [tuple(map(int,input().split())) for _ in range(M)] for x in A:
    bc.append((1,x)) x A bc.append((1,x)) bc.append bc append (1,x) 1 x bc.sort(key=lambda x:x[1], reverse=True) bc.sort bc sort key=lambda x:x[1] key lambda x:x[1] x[1] x 1 x reverse=True reverse True A = [] A [] for b,c in bc:
    while len(A) < N and b > 0:
        b -= 1
        A.append(c)
    if len(A) == N:
        break b c bc while len(A) < N and b > 0:
        b -= 1
        A.append(c)
     len(A) < N and b > 0 len(A) < N len(A) len A N b > 0 b 0 b -= 1 b 1 A.append(c) A.append A append c if len(A) == N:
        break len(A) == N len(A) len A N break A.sort(reverse=True) A.sort A sort reverse=True reverse True print(sum(A)) print sum(A) sum A bc = [tuple(map(int,input().split())) for _ in range(M)] [tuple(map(int,input().split())) for _ in range(M)] bc N,M = map(int,input().split()) map(int,input().split()) N b -= 1 1 b A = [] [] A M = map(int,input().split()) map(int,input().split()) M A = list(map(int,input().split())) list(map(int,input().split())) A
from collections import deque
N,M = map(int,input().split())
A = list(map(int,input().split()))
bc = [tuple(map(int,input().split())) for _ in range(M)]
for x in A:
    bc.append((1,x))
bc.sort(key=lambda x:x[1], reverse=True)
A = []
for b,c in bc:
    while len(A) < N and b > 0:
        b -= 1
        A.append(c)
    if len(A) == N:
        break
A.sort(reverse=True)
print(sum(A))