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

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

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





table = {}

for Ai in A:

    table[str(Ai)] = 0

for Bi, Ci in BC:

    table[str(Ci)] = 0

    

for Ai in A:

    table[str(Ai)] += 1



for Bi, Ci in BC:

    table[str(Ci)] += Bi



table2 = [(int(key), value) for key, value in list(table.items())]

table2.sort(key=lambda x: -x[0])



ans = ans_cnt = 0

for key, value in table2:

    # print("#", key, value, ans_cnt, ans)

    if ans_cnt + value >= N:

        ans += key * (N - ans_cnt)

        break

    else:

        ans_cnt += value

        ans += key * value



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

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

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



A.sort()

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



idx = 0

X = [0] * N

for Bi, Ci in BC:

    for _ in range(Bi):

        if idx >= N: break

        X[idx] = Ci

        idx += 1

    #

    if idx >= N: break



ans = [None] * N

for i in range(N):

    ans[i] = max(A[i], X[i])



print((sum(ans)))
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
table = {}
for Ai in A:
    table[str(Ai)] = 0
for Bi, Ci in BC:
    table[str(Ci)] = 0
for Ai in A:
    table[str(Ai)] += 1
for Bi, Ci in BC:
    table[str(Ci)] += Bi
table2 = [(int(key), value) for key, value in list(table.items())]
table2.sort(key=lambda x: -x[0])
ans = ans_cnt = 0
for key, value in table2:
    # print("#", key, value, ans_cnt, ans)
    if ans_cnt + value >= N:
        ans += key * (N - ans_cnt)
        break
    else:
        ans_cnt += value
        ans += key * value
print(ans)

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
A.sort()
BC.sort(key=lambda x: -x[1])
idx = 0
X = [0] * N
for Bi, Ci in BC:
    for _ in range(Bi):
        if idx >= N:
            break
        X[idx] = Ci
        idx += 1
    #
    if idx >= N:
        break
ans = [None] * N
for i in range(N):
    ans[i] = max(A[i], X[i])
print((sum(ans)))

-table = {} -for Ai in A: -    table[str(Ai)] = 0 +A.sort() +BC.sort(key=lambda x: -x[1]) +idx = 0 +X = [0] * N -    table[str(Ci)] = 0 -for Ai in A: -    table[str(Ai)] += 1 -for Bi, Ci in BC: -    table[str(Ci)] += Bi -table2 = [(int(key), value) for key, value in list(table.items())] -table2.sort(key=lambda x: -x[0]) -ans = ans_cnt = 0 -for key, value in table2: -    # print("#", key, value, ans_cnt, ans) -    if ans_cnt + value >= N: -        ans += key * (N - ans_cnt) +    for _ in range(Bi): +        if idx >= N: +            break +        X[idx] = Ci +        idx += 1 +    # +    if idx >= N: -    else: -        ans_cnt += value -        ans += key * value -print(ans) +ans = [None] * N +for i in range(N): +    ans[i] = max(A[i], X[i]) +print((sum(ans)))