N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
op = []
for i in range(M):
    b, c = map(int, input().split())
    op.append((c, b))
op.sort(reverse=True)
sum = 0
j = 0
for c,b in op:
    while j < N and b > 0 and A[j] < c:
        sum += c
        b -= 1
        j = j + 1
while j < N:
    sum += A[j]
    j += 1
print(sum) 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 op = [] op [] for i in range(M):
    b, c = map(int, input().split())
    op.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 op.append((c, b)) op.append op append (c, b) c b op.sort(reverse=True) op.sort op sort reverse=True reverse True sum = 0 sum 0 j = 0 j 0 for c,b in op:
    while j < N and b > 0 and A[j] < c:
        sum += c
        b -= 1
        j = j + 1 c b op while j < N and b > 0 and A[j] < c:
        sum += c
        b -= 1
        j = j + 1 j < N and b > 0 and A[j] < c j < N and b > 0 j < N j N b > 0 b 0 A[j] < c A[j] A j c sum += c sum c b -= 1 b 1 j = j + 1 j j + 1 j 1 while j < N:
    sum += A[j]
    j += 1 j < N j N sum += A[j] sum A[j] A j j += 1 j 1 print(sum) print sum j = 0 0 j A = list(map(int, input().split())) list(map(int, input().split())) A c = map(int, input().split()) map(int, input().split()) c j = j + 1 j + 1 j sum = 0 0 sum M = map(int, input().split()) map(int, input().split()) M b -= 1 1 b N, M = map(int, input().split()) map(int, input().split()) N b, c = map(int, input().split()) map(int, input().split()) b sum += A[j] A[j] sum j += 1 1 j sum += c c sum op = [] [] op
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
op = []
for i in range(M):
    b, c = map(int, input().split())
    op.append((c, b))
op.sort(reverse=True)
sum = 0
j = 0
for c,b in op:
    while j < N and b > 0 and A[j] < c:
        sum += c
        b -= 1
        j = j + 1
while j < N:
    sum += A[j]
    j += 1
print(sum)