import heapq

N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
B = [list(map(int,input().split())) for i in range(M)]
B = sorted(B, key = lambda x: x[1])[::-1]

heapq.heapify(A)
cnt = 0
for i in range(M):
    for _ in range(B[i][0]):  heapq.heappush(A, max(heapq.heappop(A), B[i][1]))
    cnt += B[i][0]
    if cnt >= N:  break
print(sum(A)) import heapq heapq 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 list(map(int,input().split())) for i in range(M) for i in range(M) i range(M) range M for i in range(M) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split B = [list(map(int,input().split())) for i in range(M)] B [list(map(int,input().split())) for i in range(M)] B = sorted(B, key = lambda x: x[1])[::-1] B sorted(B, key = lambda x: x[1])[::-1] (B, key = lambda x: x[1]) sorted B key = lambda x: x[1] key lambda x: x[1] x[1] x 1 x ::-1 -1 heapq.heapify(A) heapq.heapify heapq heapify A cnt = 0 cnt 0 for i in range(M):
    for _ in range(B[i][0]):  heapq.heappush(A, max(heapq.heappop(A), B[i][1]))
    cnt += B[i][0]
    if cnt >= N:  break i range(M) range M for _ in range(B[i][0]):  heapq.heappush(A, max(heapq.heappop(A), B[i][1]))
     _ range(B[i][0]) range B[i][0] [i] B i 0 cnt += B[i][0] cnt B[i][0] [i] B i 0 if cnt >= N:  b cnt >= N cnt N print(sum(A)) print sum(A) sum A N, M = list(map(int,input().split())) list(map(int,input().split())) N cnt += B[i][0] B[i][0] cnt B = [list(map(int,input().split())) for i in range(M)] [list(map(int,input().split())) for i in range(M)] B A = list(map(int,input().split())) list(map(int,input().split())) A cnt = 0 0 cnt B = sorted(B, key = lambda x: x[1])[::-1] sorted(B, key = lambda x: x[1])[::-1] B M = list(map(int,input().split())) list(map(int,input().split())) M
import heapq

N, M = list(map(int,input().split()))
A = list(map(int,input().split()))
B = [list(map(int,input().split())) for i in range(M)]
B = sorted(B, key = lambda x: x[1])[::-1]

heapq.heapify(A)
cnt = 0
for i in range(M):
    for _ in range(B[i][0]):  heapq.heappush(A, max(heapq.heappop(A), B[i][1]))
    cnt += B[i][0]
    if cnt >= N:  break
print(sum(A))