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

A = sorted(list(map(int,input().split())))

L = []

for k in range(M):

    B, C = list(map(int,input().split()))

    L.append([B,C])

L = sorted(L,key=lambda x: -x[1])

ans = 0

i = 0

for k in range(N):

    if i < M:

        if A[k] < L[i][1]:

            L[i][0] -= 1

            ans += L[i][1]

            if L[i][0] == 0:

                i += 1

        else:

            ans += A[k]

    else:

        ans += A[k]

print(ans)

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

A = sorted(list(map(int,input().split())))

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

D = sorted(D, key = lambda x: -x[1])

D.append([10**9+1,-1])

t = 0

ans = 0

for k in range(N):

    if A[k] < D[t][1]:

        ans += D[t][1]

        D[t][0] -= 1

        if D[t][0] == 0:

            t += 1

    else:

        ans += A[k]



print(ans)

N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
L = []
for k in range(M):
    B, C = list(map(int, input().split()))
    L.append([B, C])
L = sorted(L, key=lambda x: -x[1])
ans = 0
i = 0
for k in range(N):
    if i < M:
        if A[k] < L[i][1]:
            L[i][0] -= 1
            ans += L[i][1]
            if L[i][0] == 0:
                i += 1
        else:
            ans += A[k]
    else:
        ans += A[k]
print(ans)

N, M = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
D = [list(map(int, input().split())) for k in range(M)]
D = sorted(D, key=lambda x: -x[1])
D.append([10**9 + 1, -1])
t = 0
ans = 0
for k in range(N):
    if A[k] < D[t][1]:
        ans += D[t][1]
        D[t][0] -= 1
        if D[t][0] == 0:
            t += 1
    else:
        ans += A[k]
print(ans)

-L = [] -for k in range(M): -    B, C = list(map(int, input().split())) -    L.append([B, C]) -L = sorted(L, key=lambda x: -x[1]) +D = [list(map(int, input().split())) for k in range(M)] +D = sorted(D, key=lambda x: -x[1]) +D.append([10**9 + 1, -1]) +t = 0 -i = 0 -    if i < M: -        if A[k] < L[i][1]: -            L[i][0] -= 1 -            ans += L[i][1] -            if L[i][0] == 0: -                i += 1 -        else: -            ans += A[k] +    if A[k] < D[t][1]: +        ans += D[t][1] +        D[t][0] -= 1 +        if D[t][0] == 0: +            t += 1