from bisect import bisect_left

from operator import itemgetter



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

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

BC = []

X = []

for _ in range(M):

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

    X.append((b, c))



X = sorted(X, key=itemgetter(1), reverse=True)



for b, c in X:

    BC.extend([c] * b)

    if len(BC) >= N:

        break



Y = A + BC

Y.sort(reverse=True)

answer = sum(Y[:N])

print(answer)
# coding: utf-8

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, M = lr()

A = lr()

BC = [lr() for _ in range(M)]

BC.sort(key=lambda x: x[1], reverse=True)

D = []

count = 0

for b, c in BC:

    x = [c] * b

    D.extend(x)

    count += b

    if count >= N:

        break



E = A + D

E.sort(reverse=True)

answer = sum(E[:N])

print(answer)

from bisect import bisect_left
from operator import itemgetter

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = []
X = []
for _ in range(M):
    b, c = list(map(int, input().split()))
    X.append((b, c))
X = sorted(X, key=itemgetter(1), reverse=True)
for b, c in X:
    BC.extend([c] * b)
    if len(BC) >= N:
        break
Y = A + BC
Y.sort(reverse=True)
answer = sum(Y[:N])
print(answer)

# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
A = lr()
BC = [lr() for _ in range(M)]
BC.sort(key=lambda x: x[1], reverse=True)
D = []
count = 0
for b, c in BC:
    x = [c] * b
    D.extend(x)
    count += b
    if count >= N:
        break
E = A + D
E.sort(reverse=True)
answer = sum(E[:N])
print(answer)

-from bisect import bisect_left -from operator import itemgetter +# coding: utf-8 +import sys -N, M = list(map(int, input().split())) -A = list(map(int, input().split())) -BC = [] -X = [] -for _ in range(M): -    b, c = list(map(int, input().split())) -    X.append((b, c)) -X = sorted(X, key=itemgetter(1), reverse=True) -for b, c in X: -    BC.extend([c] * b) -    if len(BC) >= N: +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +N, M = lr() +A = lr() +BC = [lr() for _ in range(M)] +BC.sort(key=lambda x: x[1], reverse=True) +D = [] +count = 0 +for b, c in BC: +    x = [c] * b +    D.extend(x) +    count += b +    if count >= N: -Y = A + BC -Y.sort(reverse=True) -answer = sum(Y[:N]) +E = A + D +E.sort(reverse=True) +answer = sum(E[:N])