from bisect import *
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
data = []
for _ in range(M):
    B, C = map(int, input().split())
    data.append((B, C))
data.sort(key=lambda x:x[1], reverse=True)

D = []
for B, C in data:
    i = bisect_left(A, C)
    p = min(B, i)
    if len(D)+p <N:
        D += [C]*p
    else:
        D += [C]*(N-len(D))
        break

res = 0
for i in range(N):
    if i>=len(D) or A[i] > D[i]:
        res += A[i]
    else:
        res += D[i]
print(res) from bisect import * 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 data = [] data [] for _ in range(M):
    B, C = map(int, input().split())
    data.append((B, C)) _ range(M) range M B, C = map(int, input().split()) B map(int, input().split()) map int input().split() ().split () input split C data.append((B, C)) data.append data append (B, C) B C data.sort(key=lambda x:x[1], reverse=True) data.sort data sort key=lambda x:x[1] key lambda x:x[1] x[1] x 1 x reverse=True reverse True D = [] D [] for B, C in data:
    i = bisect_left(A, C)
    p = min(B, i)
    if len(D)+p <N:
        D += [C]*p
    else:
        D += [C]*(N-len(D))
        break B C data i = bisect_left(A, C) i bisect_left(A, C) bisect_left A C p = min(B, i) p min(B, i) min B i if len(D)+p <N:
        D += [C]*p
    else:
        D += [C]*(N-len(D))
        break len(D)+p <N len(D)+p len(D) len D p N D += [C]*p D [C]*p [C] C p D += [C]*(N-len(D)) D [C]*(N-len(D)) [C] C N-len(D) N len(D) len D break res = 0 res 0 for i in range(N):
    if i>=len(D) or A[i] > D[i]:
        res += A[i]
    else:
        res += D[i] i range(N) range N if i>=len(D) or A[i] > D[i]:
        res += A[i]
    else:
        res += D[i] i>=len(D) or A[i] > D[i] i>=len(D) i len(D) len D A[i] > D[i] A[i] A i D[i] D i res += A[i] res A[i] A i res += D[i] res D[i] D i print(res) print res data = [] [] data D += [C]*(N-len(D)) [C]*(N-len(D)) D res += D[i] D[i] res N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M C = map(int, input().split()) map(int, input().split()) C res = 0 0 res D = [] [] D p = min(B, i) min(B, i) p res += A[i] A[i] res A = list(map(int, input().split())) list(map(int, input().split())) A B, C = map(int, input().split()) map(int, input().split()) B i = bisect_left(A, C) bisect_left(A, C) i D += [C]*p [C]*p D
from bisect import *
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
data = []
for _ in range(M):
    B, C = map(int, input().split())
    data.append((B, C))
data.sort(key=lambda x:x[1], reverse=True)

D = []
for B, C in data:
    i = bisect_left(A, C)
    p = min(B, i)
    if len(D)+p <N:
        D += [C]*p
    else:
        D += [C]*(N-len(D))
        break

res = 0
for i in range(N):
    if i>=len(D) or A[i] > D[i]:
        res += A[i]
    else:
        res += D[i]
print(res)