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

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

L=[(1,a) for a in A]

for _ in range(M):

  b,c=list(map(int,input().split()))

  L.append((b,c))

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

ans,k=0,0

for n,a in L:

  if n+k>=N:

    ans+=a*(N-k)

    break

  else:

    ans+=a*n

    k+=n

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

L=[(1,a) for a in map(int,input().split())]

for _ in range(M):

  L.append(tuple(map(int,input().split())))

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

ans,k=0,0

for n,a in L:

  if n+k>=N:

    ans+=a*(N-k)

    break

  else:

    ans+=a*n

    k+=n

print(ans)
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
L = [(1, a) for a in A]
for _ in range(M):
    b, c = list(map(int, input().split()))
    L.append((b, c))
L = sorted(L, key=lambda x: x[1], reverse=True)
ans, k = 0, 0
for n, a in L:
    if n + k >= N:
        ans += a * (N - k)
        break
    else:
        ans += a * n
        k += n
print(ans)

N, M = list(map(int, input().split()))
L = [(1, a) for a in map(int, input().split())]
for _ in range(M):
    L.append(tuple(map(int, input().split())))
L = sorted(L, key=lambda x: x[1], reverse=True)
ans, k = 0, 0
for n, a in L:
    if n + k >= N:
        ans += a * (N - k)
        break
    else:
        ans += a * n
        k += n
print(ans)

-A = list(map(int, input().split())) -L = [(1, a) for a in A] +L = [(1, a) for a in map(int, input().split())] -    b, c = list(map(int, input().split())) -    L.append((b, c)) +    L.append(tuple(map(int, input().split())))