N, M = list(map(int, input().split()))

lst_A = list(map(int, input().split()))

lst_BC = [list(map(int, input().split())) for _ in range(M)]





lst_A.sort()

# lst_BC.sort(key=lambda x:-x[1])

lst_BC.sort(key=lambda x:x[1], reverse=True)

# print(lst_A)

# print(lst_BC)





lst_D = []

for b, c in lst_BC:

    lst_D += [c] * min(b, N - len(lst_D))

lst_D = lst_D + [0] * (N - len(lst_D))

# print(lst_D)





for i in range(N):

    if lst_A[i] >= lst_D[i]:

        break

    lst_A[i] = lst_D[i]

# print(lst_A)





print((sum(lst_A)))
N, M = list(map(int, input().split()))

lst_A = list(map(int, input().split()))

lst_BC = [tuple(map(int, input().split())) for _ in range(M)]





lst_A.sort()

lst_BC.sort(key=lambda x:x[1], reverse=True)





lst_D = []

for b, c in lst_BC:

    lst_D += [c] * min(b, N - len(lst_D))

lst_D = lst_D + [0] * (N - len(lst_D))





for i in range(N):

    if lst_A[i] >= lst_D[i]:

        break

    lst_A[i] = lst_D[i]





print((sum(lst_A)))
N, M = list(map(int, input().split()))
lst_A = list(map(int, input().split()))
lst_BC = [list(map(int, input().split())) for _ in range(M)]
lst_A.sort()
# lst_BC.sort(key=lambda x:-x[1])
lst_BC.sort(key=lambda x: x[1], reverse=True)
# print(lst_A)
# print(lst_BC)
lst_D = []
for b, c in lst_BC:
    lst_D += [c] * min(b, N - len(lst_D))
lst_D = lst_D + [0] * (N - len(lst_D))
# print(lst_D)
for i in range(N):
    if lst_A[i] >= lst_D[i]:
        break
    lst_A[i] = lst_D[i]
# print(lst_A)
print((sum(lst_A)))

N, M = list(map(int, input().split()))
lst_A = list(map(int, input().split()))
lst_BC = [tuple(map(int, input().split())) for _ in range(M)]
lst_A.sort()
lst_BC.sort(key=lambda x: x[1], reverse=True)
lst_D = []
for b, c in lst_BC:
    lst_D += [c] * min(b, N - len(lst_D))
lst_D = lst_D + [0] * (N - len(lst_D))
for i in range(N):
    if lst_A[i] >= lst_D[i]:
        break
    lst_A[i] = lst_D[i]
print((sum(lst_A)))

-lst_BC = [list(map(int, input().split())) for _ in range(M)] +lst_BC = [tuple(map(int, input().split())) for _ in range(M)] -# lst_BC.sort(key=lambda x:-x[1]) -# print(lst_A) -# print(lst_BC) -# print(lst_D) -# print(lst_A)