N, M = [int(x) for x in input().split()]
A = sorted([int(x) for x in input().split()])

data = []
for i in range(M):
    B, C = [int(x) for x in input().split()]
    data.append([C, B])
data = sorted(data, reverse=True)

D = []
i, tot = 0, 0
while tot < N and i < M:
    C, B = data[i][0], data[i][1]
    for _ in range(B):
        D.append(C)
        tot += 1
        if tot >= N:
            break
    i += 1

i = 0
while i < min(N, len(D)) and A[i] < D[i]:
    i += 1

ans = sum(D[:i] + A[i:])
print(ans) int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x N, M = [int(x) for x in input().split()] N [int(x) for x in input().split()] M int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x A = sorted([int(x) for x in input().split()]) A sorted([int(x) for x in input().split()]) sorted [int(x) for x in input().split()] data = [] data [] for i in range(M):
    B, C = [int(x) for x in input().split()]
    data.append([C, B]) i range(M) range M int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x B, C = [int(x) for x in input().split()] B [int(x) for x in input().split()] C data.append([C, B]) data.append data append [C, B] C B data = sorted(data, reverse=True) data sorted(data, reverse=True) sorted data reverse=True reverse True D = [] D [] i, tot = 0, 0 i 0 tot 0 while tot < N and i < M:
    C, B = data[i][0], data[i][1]
    for _ in range(B):
        D.append(C)
        tot += 1
        if tot >= N:
            break
    i += 1 tot < N and i < M tot < N tot N i < M i M C, B = data[i][0], data[i][1] C data[i][0] [i] data i 0 B data[i][1] [i] data i 1 for _ in range(B):
        D.append(C)
        tot += 1
        if tot >= N:
            break
     _ range(B) range B D.append(C) D.append D append C tot += 1 tot 1 if tot >= N:
            break
     tot >= N tot N break i += 1 i 1 i = 0 i 0 while i < min(N, len(D)) and A[i] < D[i]:
    i += 1 i < min(N, len(D)) and A[i] < D[i] i < min(N, len(D)) i min(N, len(D)) min N len(D) len D A[i] < D[i] A[i] A i D[i] D i i += 1 i 1 ans = sum(D[:i] + A[i:]) ans sum(D[:i] + A[i:]) sum D[:i] + A[i:] D[:i] D :i i A[i:] A i: i print(ans) print ans data = [] [] data ans = sum(D[:i] + A[i:]) sum(D[:i] + A[i:]) ans C, B = data[i][0], data[i][1] data[i][0] C tot += 1 1 tot A = sorted([int(x) for x in input().split()]) sorted([int(x) for x in input().split()]) A B, C = [int(x) for x in input().split()] [int(x) for x in input().split()] B i = 0 0 i M = [int(x) for x in input().split()] [int(x) for x in input().split()] M data = sorted(data, reverse=True) sorted(data, reverse=True) data i += 1 1 i N, M = [int(x) for x in input().split()] [int(x) for x in input().split()] N B = data[i][0], data[i][1] data[i][1] B i, tot = 0, 0 0 i tot = 0, 0 0 tot D = [] [] D C = [int(x) for x in input().split()] [int(x) for x in input().split()] C i += 1 1 i
N, M = [int(x) for x in input().split()]
A = sorted([int(x) for x in input().split()])

data = []
for i in range(M):
    B, C = [int(x) for x in input().split()]
    data.append([C, B])
data = sorted(data, reverse=True)

D = []
i, tot = 0, 0
while tot < N and i < M:
    C, B = data[i][0], data[i][1]
    for _ in range(B):
        D.append(C)
        tot += 1
        if tot >= N:
            break
    i += 1

i = 0
while i < min(N, len(D)) and A[i] < D[i]:
    i += 1

ans = sum(D[:i] + A[i:])
print(ans)