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

num = 0
for i in range(M):
    for j in range(B[i][0]):
        if num > N-1:
            break
        if A[num] < B[i][1]:
            A[num] = B[i][1]
            num += 1
        else:
            break

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 list(map(int,input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ 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 _ in range(M)] B [list(map(int,input().split())) for _ in range(M)] B.sort(key = lambda x:x[1]) B.sort B sort key = lambda x:x[1] key lambda x:x[1] x[1] x 1 x B = list(reversed(B)) B list(reversed(B)) list reversed(B) reversed B A.sort() A.sort A sort num = 0 num 0 for i in range(M):
    for j in range(B[i][0]):
        if num > N-1:
            break
        if A[num] < B[i][1]:
            A[num] = B[i][1]
            num += 1
        else:
            break i range(M) range M for j in range(B[i][0]):
        if num > N-1:
            break
        if A[num] < B[i][1]:
            A[num] = B[i][1]
            num += 1
        else:
            break j range(B[i][0]) range B[i][0] [i] B i 0 if num > N-1:
            break
         num > N-1 num N-1 N 1 break if A[num] < B[i][1]:
            A[num] = B[i][1]
            num += 1
        else:
            break A[num] < B[i][1] A[num] A num B[i][1] [i] B i 1 A[num] = B[i][1] A[num] A num B[i][1] [i] B i 1 num += 1 num 1 break print(sum(A)) print sum(A) sum A B = list(reversed(B)) list(reversed(B)) B B = [list(map(int,input().split())) for _ in range(M)] [list(map(int,input().split())) for _ in range(M)] B num = 0 0 num N,M = map(int,input().split()) map(int,input().split()) N A = list(map(int,input().split())) list(map(int,input().split())) A num += 1 1 num M = map(int,input().split()) map(int,input().split()) M
N,M = map(int,input().split())
A = list(map(int,input().split()))
B = [list(map(int,input().split())) for _ in range(M)]
B.sort(key = lambda x:x[1])
B = list(reversed(B))
A.sort()

num = 0
for i in range(M):
    for j in range(B[i][0]):
        if num > N-1:
            break
        if A[num] < B[i][1]:
            A[num] = B[i][1]
            num += 1
        else:
            break

print(sum(A))