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

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



# 二次元配列を作る

BC = []

for i in range(M):

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

    BC.append([b, c])



BC = sorted(BC, reverse=True, key=lambda x: x[1])  # Cの値で降順にソートされる



cnt = 0

com = []



for b, c in BC:

    cnt += b

    if cnt > N:  # 操作を加える回数がNを超えることはない

        add = N-cnt+b  # comの要素数の調整

        com.extend([c]*add)

        break

    else:

        com.extend([c]*b)



A.extend(com)



A.sort(reverse=True)

print((sum(A[:N])))

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

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

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

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



hold = []

now = 0

for k, v in magic:

    hold.extend([v]*k)

    now += k

    if now >= N:

        break

A.extend(hold)

A.sort(reverse=True)

print((sum(A[:N])))

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
# 二次元配列を作る
BC = []
for i in range(M):
    b, c = list(map(int, input().split()))
    BC.append([b, c])
BC = sorted(BC, reverse=True, key=lambda x: x[1])  # Cの値で降順にソートされる
cnt = 0
com = []
for b, c in BC:
    cnt += b
    if cnt > N:  # 操作を加える回数がNを超えることはない
        add = N - cnt + b  # comの要素数の調整
        com.extend([c] * add)
        break
    else:
        com.extend([c] * b)
A.extend(com)
A.sort(reverse=True)
print((sum(A[:N])))

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
magic = [list(map(int, input().split())) for _ in range(M)]
magic = sorted(magic, key=lambda x: -x[1])
hold = []
now = 0
for k, v in magic:
    hold.extend([v] * k)
    now += k
    if now >= N:
        break
A.extend(hold)
A.sort(reverse=True)
print((sum(A[:N])))

-# 二次元配列を作る -BC = [] -for i in range(M): -    b, c = list(map(int, input().split())) -    BC.append([b, c]) -BC = sorted(BC, reverse=True, key=lambda x: x[1])  # Cの値で降順にソートされる -cnt = 0 -com = [] -for b, c in BC: -    cnt += b -    if cnt > N:  # 操作を加える回数がNを超えることはない -        add = N - cnt + b  # comの要素数の調整 -        com.extend([c] * add) +magic = [list(map(int, input().split())) for _ in range(M)] +magic = sorted(magic, key=lambda x: -x[1]) +hold = [] +now = 0 +for k, v in magic: +    hold.extend([v] * k) +    now += k +    if now >= N: -    else: -        com.extend([c] * b) -A.extend(com) +A.extend(hold)