N, M = map(int, input().split())
A = list(map(lambda x: int(x), input().split()))
Q = []

for i in range(M):
    Q.append(tuple(map(int, input().split())))

A.sort()

Q.sort(key=lambda x: x[1], reverse=True)

cur = 0
for i in range(M):
    cnt = Q[i][0]
    while cnt > 0 and cur < N:
        if A[cur] >= Q[i][1]:
            break
        A[cur] = Q[i][1]
        cur += 1
        cnt -= 1

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(lambda x: int(x), input().split())) A list(map(lambda x: int(x), input().split())) list map(lambda x: int(x), input().split()) map lambda x: int(x) int(x) int x x input().split() ().split () input split Q = [] Q [] for i in range(M):
    Q.append(tuple(map(int, input().split()))) i range(M) range M Q.append(tuple(map(int, input().split()))) Q.append Q append tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split A.sort() A.sort A sort Q.sort(key=lambda x: x[1], reverse=True) Q.sort Q sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True cur = 0 cur 0 for i in range(M):
    cnt = Q[i][0]
    while cnt > 0 and cur < N:
        if A[cur] >= Q[i][1]:
            break
        A[cur] = Q[i][1]
        cur += 1
        cnt -= 1 i range(M) range M cnt = Q[i][0] cnt Q[i][0] [i] Q i 0 while cnt > 0 and cur < N:
        if A[cur] >= Q[i][1]:
            break
        A[cur] = Q[i][1]
        cur += 1
        cnt -= 1 cnt > 0 and cur < N cnt > 0 cnt 0 cur < N cur N if A[cur] >= Q[i][1]:
            break
         A[cur] >= Q[i][1] A[cur] A cur Q[i][1] [i] Q i 1 break A[cur] = Q[i][1] A[cur] A cur Q[i][1] [i] Q i 1 cur += 1 cur 1 cnt -= 1 cnt 1 print(sum(A)) print sum(A) sum A cur += 1 1 cur M = map(int, input().split()) map(int, input().split()) M N, M = map(int, input().split()) map(int, input().split()) N Q = [] [] Q A = list(map(lambda x: int(x), input().split())) list(map(lambda x: int(x), input().split())) A cur = 0 0 cur cnt = Q[i][0] Q[i][0] cnt cnt -= 1 1 cnt
N, M = map(int, input().split())
A = list(map(lambda x: int(x), input().split()))
Q = []

for i in range(M):
    Q.append(tuple(map(int, input().split())))

A.sort()

Q.sort(key=lambda x: x[1], reverse=True)

cur = 0
for i in range(M):
    cnt = Q[i][0]
    while cnt > 0 and cur < N:
        if A[cur] >= Q[i][1]:
            break
        A[cur] = Q[i][1]
        cur += 1
        cnt -= 1

print(sum(A))