N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for i in range(M):
    b, c = map(int, input().split())
    BC.append([b,c])

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

a_itr = 0
bc_itr = 0
bc = BC[0]
while a_itr < N:
    if bc[0] == 0:
        bc_itr += 1
        if bc_itr < M:
            bc = BC[bc_itr]
        else:
            break
    else:
        if A[a_itr] < bc[1]:
            A[a_itr] = bc[1]
            a_itr += 1
            bc[0] -= 1
        else:
            break

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(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split BC = [] BC [] for i in range(M):
    b, c = map(int, input().split())
    BC.append([b,c]) i range(M) range M b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c BC.append([b,c]) BC.append BC append [b,c] b c A = sorted(A) A sorted(A) sorted A 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 a_itr = 0 a_itr 0 bc_itr = 0 bc_itr 0 bc = BC[0] bc BC[0] BC 0 while a_itr < N:
    if bc[0] == 0:
        bc_itr += 1
        if bc_itr < M:
            bc = BC[bc_itr]
        else:
            break
    else:
        if A[a_itr] < bc[1]:
            A[a_itr] = bc[1]
            a_itr += 1
            bc[0] -= 1
        else:
            break a_itr < N a_itr N if bc[0] == 0:
        bc_itr += 1
        if bc_itr < M:
            bc = BC[bc_itr]
        else:
            break
    else:
        if A[a_itr] < bc[1]:
            A[a_itr] = bc[1]
            a_itr += 1
            bc[0] -= 1
        else:
            break bc[0] == 0 bc[0] bc 0 0 bc_itr += 1 bc_itr 1 if bc_itr < M:
            bc = BC[bc_itr]
        else:
            break
     bc_itr < M bc_itr M bc = BC[bc_itr] bc BC[bc_itr] BC bc_itr break if A[a_itr] < bc[1]:
            A[a_itr] = bc[1]
            a_itr += 1
            bc[0] -= 1
        else:
            break A[a_itr] < bc[1] A[a_itr] A a_itr bc[1] bc 1 A[a_itr] = bc[1] A[a_itr] A a_itr bc[1] bc 1 a_itr += 1 a_itr 1 bc[0] -= 1 bc[0] bc 0 1 break print(sum(A)) print sum(A) sum A A = list(map(int, input().split())) list(map(int, input().split())) A A = sorted(A) sorted(A) A N, M = map(int, input().split()) map(int, input().split()) N BC = [] [] BC M = map(int, input().split()) map(int, input().split()) M bc_itr += 1 1 bc_itr c = map(int, input().split()) map(int, input().split()) c a_itr = 0 0 a_itr BC = sorted(BC, key=lambda x:x[1], reverse=True) sorted(BC, key=lambda x:x[1], reverse=True) BC bc_itr = 0 0 bc_itr bc = BC[0] BC[0] bc a_itr += 1 1 a_itr b, c = map(int, input().split()) map(int, input().split()) b bc = BC[bc_itr] BC[bc_itr] bc
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for i in range(M):
    b, c = map(int, input().split())
    BC.append([b,c])

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

a_itr = 0
bc_itr = 0
bc = BC[0]
while a_itr < N:
    if bc[0] == 0:
        bc_itr += 1
        if bc_itr < M:
            bc = BC[bc_itr]
        else:
            break
    else:
        if A[a_itr] < bc[1]:
            A[a_itr] = bc[1]
            a_itr += 1
            bc[0] -= 1
        else:
            break

print(sum(A))

