
N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

CB = []
for i in range(M):
    B, C = map(int, input().split())
    CB.append([C, B])
    
CB.sort(reverse=True)

idx = 0
c = 0
for i in range(N):
    if A[i] < CB[idx][0]:
        A[i] = CB[idx][0]
        c += 1
    if CB[idx][1] <= c:
        idx += 1
        c = 0
    if idx >= M:
        break
    #print(A)
        
print(sum(A)) 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 A.sort() A.sort A sort CB = [] CB [] for i in range(M):
    B, C = map(int, input().split())
    CB.append([C, B])
     i range(M) range M B, C = map(int, input().split()) B map(int, input().split()) map int input().split() ().split () input split C CB.append([C, B]) CB.append CB append [C, B] C B CB.sort(reverse=True) CB.sort CB sort reverse=True reverse True idx = 0 idx 0 c = 0 c 0 for i in range(N):
    if A[i] < CB[idx][0]:
        A[i] = CB[idx][0]
        c += 1
    if CB[idx][1] <= c:
        idx += 1
        c = 0
    if idx >= M:
        break
    #print(A)
         i range(N) range N if A[i] < CB[idx][0]:
        A[i] = CB[idx][0]
        c += 1
     A[i] < CB[idx][0] A[i] A i CB[idx][0] [idx] CB idx 0 A[i] = CB[idx][0] A[i] A i CB[idx][0] [idx] CB idx 0 c += 1 c 1 if CB[idx][1] <= c:
        idx += 1
        c = 0
     CB[idx][1] <= c CB[idx][1] [idx] CB idx 1 c idx += 1 idx 1 c = 0 c 0 if idx >= M:
        break
    #print(A)
         idx >= M idx M break print(sum(A)) print sum(A) sum A c = 0 0 c idx += 1 1 idx A = list(map(int, input().split())) list(map(int, input().split())) A M = map(int, input().split()) map(int, input().split()) M c = 0 0 c CB = [] [] CB N, M = map(int, input().split()) map(int, input().split()) N C = map(int, input().split()) map(int, input().split()) C c += 1 1 c B, C = map(int, input().split()) map(int, input().split()) B idx = 0 0 idx

N, M = map(int, input().split())
A = list(map(int, input().split()))

A.sort()

CB = []
for i in range(M):
    B, C = map(int, input().split())
    CB.append([C, B])
    
CB.sort(reverse=True)

idx = 0
c = 0
for i in range(N):
    if A[i] < CB[idx][0]:
        A[i] = CB[idx][0]
        c += 1
    if CB[idx][1] <= c:
        idx += 1
        c = 0
    if idx >= M:
        break
    #print(A)
        
print(sum(A))