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

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

xs = []

for _ in range(M):

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

    xs.append((c, b))

for a in As:

    xs.append((a, 1))

xs.sort()

c = 0

r = 0

for x in xs[::-1]:

    c += x[1]

    if c >= N:

        r += x[0] * (N - (c-x[1]))

        break

    else:

        r += x[0] * x[1]

print(r)

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

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



X = []

for _ in range(M):

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

    X.append((b, c))

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

Y = []

for i in range(M):

    ly = len(Y)

    b, c = X[i]

    if ly + b < N:

        Y += [c] * b

    else:

        Y += [c] * (N-ly)

Z=A+Y 

print((sum(sorted(Z)[::-1][:N])))

N, M = list(map(int, input().split()))
As = list(map(int, input().split()))
xs = []
for _ in range(M):
    b, c = list(map(int, input().split()))
    xs.append((c, b))
for a in As:
    xs.append((a, 1))
xs.sort()
c = 0
r = 0
for x in xs[::-1]:
    c += x[1]
    if c >= N:
        r += x[0] * (N - (c - x[1]))
        break
    else:
        r += x[0] * x[1]
print(r)

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
X = []
for _ in range(M):
    b, c = list(map(int, input().split()))
    X.append((b, c))
X = sorted(X, key=lambda x: -x[1])
Y = []
for i in range(M):
    ly = len(Y)
    b, c = X[i]
    if ly + b < N:
        Y += [c] * b
    else:
        Y += [c] * (N - ly)
Z = A + Y
print((sum(sorted(Z)[::-1][:N])))

-As = list(map(int, input().split())) -xs = [] +A = list(map(int, input().split())) +X = [] -    xs.append((c, b)) -for a in As: -    xs.append((a, 1)) -xs.sort() -c = 0 -r = 0 -for x in xs[::-1]: -    c += x[1] -    if c >= N: -        r += x[0] * (N - (c - x[1])) -        break +    X.append((b, c)) +X = sorted(X, key=lambda x: -x[1]) +Y = [] +for i in range(M): +    ly = len(Y) +    b, c = X[i] +    if ly + b < N: +        Y += [c] * b -        r += x[0] * x[1] -print(r) +        Y += [c] * (N - ly) +Z = A + Y +print((sum(sorted(Z)[::-1][:N])))