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

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

P = [(A[i], 1) for i in range(N)]

for j in range(M):

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

    P.append((C, B))

P.sort(reverse=True)

ans, cnt = 0, N

for v, c in P:

    use = min(c, cnt)

    ans += use*v

    cnt -= use

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

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

A.sort()

CB = [list(map(int, input().split()))[::-1] for _ in range(M)]

CB.sort()

C, B = list(map(list, list(zip(*CB))))

b = B.pop()

c = C.pop()

ans = []

for a in A:

    if a < c:

        ans.append(c)

        b -= 1

    else:

        ans.append(a)

    if b == 0:

        if B:

            b = B.pop()

            c = C.pop()

        else:

            c = -1



print((sum(ans)))

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
P = [(A[i], 1) for i in range(N)]
for j in range(M):
    B, C = list(map(int, input().split()))
    P.append((C, B))
P.sort(reverse=True)
ans, cnt = 0, N
for v, c in P:
    use = min(c, cnt)
    ans += use * v
    cnt -= use
print(ans)

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
CB = [list(map(int, input().split()))[::-1] for _ in range(M)]
CB.sort()
C, B = list(map(list, list(zip(*CB))))
b = B.pop()
c = C.pop()
ans = []
for a in A:
    if a < c:
        ans.append(c)
        b -= 1
    else:
        ans.append(a)
    if b == 0:
        if B:
            b = B.pop()
            c = C.pop()
        else:
            c = -1
print((sum(ans)))

-P = [(A[i], 1) for i in range(N)] -for j in range(M): -    B, C = list(map(int, input().split())) -    P.append((C, B)) -P.sort(reverse=True) -ans, cnt = 0, N -for v, c in P: -    use = min(c, cnt) -    ans += use * v -    cnt -= use -print(ans) +A.sort() +CB = [list(map(int, input().split()))[::-1] for _ in range(M)] +CB.sort() +C, B = list(map(list, list(zip(*CB)))) +b = B.pop() +c = C.pop() +ans = [] +for a in A: +    if a < c: +        ans.append(c) +        b -= 1 +    else: +        ans.append(a) +    if b == 0: +        if B: +            b = B.pop() +            c = C.pop() +        else: +            c = -1 +print((sum(ans)))