N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1], reverse=True)

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
            if n == N:
                f = 1
                break
        else:
            f = 1
    if f == 1:
        break

print(sum(A)) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = sorted(list(map(int, input().split()))) A sorted(list(map(int, input().split()))) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bc = [0] * M bc [0] * M [0] 0 M for i in range(M):
    bc[i] = list(map(int, input().split())) i range(M) range M bc[i] = list(map(int, input().split())) bc[i] bc i list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bc = sorted(bc, key= lambda x: x[1], reverse=True) bc sorted(bc, key= lambda x: x[1], reverse=True) sorted bc key= lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True n = 0 n 0 f = 0 f 0 for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
            if n == N:
                f = 1
                break
        else:
            f = 1
    if f == 1:
        break i range(M) range M for j in range(bc[i][0]):
        if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
            if n == N:
                f = 1
                break
        else:
            f = 1
     j range(bc[i][0]) range bc[i][0] [i] bc i 0 if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
            if n == N:
                f = 1
                break
        else:
            f = 1
     A[n] < bc[i][1] A[n] A n bc[i][1] [i] bc i 1 A[n] = bc[i][1] A[n] A n bc[i][1] [i] bc i 1 n += 1 n 1 if n == N:
                f = 1
                break
         n == N n N f = 1 f 1 break f = 1 f 1 if f == 1:
        break f == 1 f 1 break print(sum(A)) print sum(A) sum A N, M = map(int, input().split()) map(int, input().split()) N n += 1 1 n A = sorted(list(map(int, input().split()))) sorted(list(map(int, input().split()))) A bc = [0] * M [0] * M bc bc = sorted(bc, key= lambda x: x[1], reverse=True) sorted(bc, key= lambda x: x[1], reverse=True) bc n = 0 0 n f = 0 0 f f = 1 1 f M = map(int, input().split()) map(int, input().split()) M f = 1 1 f
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1], reverse=True)

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
            if n == N:
                f = 1
                break
        else:
            f = 1
    if f == 1:
        break

print(sum(A))