n, m = map(int, input().split())

from collections import defaultdict

cb = defaultdict(int)

for a in input().split():
    cb[int(a)] += 1

for _ in range(m):
    b, c = map(int, input().split())
    cb[c] += b

cbl = sorted(cb.items())

res = n

ans = 0

while res > 0:
    c, b = cbl.pop()
    ncount = min(res, b)
    ans += c * ncount
    res -= ncount

print(ans) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m from collections import defaultdict cb = defaultdict(int) cb defaultdict(int) defaultdict int for a in input().split():
    cb[int(a)] += 1 a input().split() ().split () input split cb[int(a)] += 1 cb[int(a)] cb int(a) int a 1 for _ in range(m):
    b, c = map(int, input().split())
    cb[c] += b _ range(m) range m b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c cb[c] += b cb[c] cb c b cbl = sorted(cb.items()) cbl sorted(cb.items()) sorted cb.items() cb.items cb items res = n res n ans = 0 ans 0 while res > 0:
    c, b = cbl.pop()
    ncount = min(res, b)
    ans += c * ncount
    res -= ncount res > 0 res 0 c, b = cbl.pop() c cbl.pop() cbl.pop cbl pop b ncount = min(res, b) ncount min(res, b) min res b ans += c * ncount ans c * ncount c ncount res -= ncount res ncount print(ans) print ans b, c = map(int, input().split()) map(int, input().split()) b cb = defaultdict(int) defaultdict(int) cb n, m = map(int, input().split()) map(int, input().split()) n b = cbl.pop() cbl.pop() b c = map(int, input().split()) map(int, input().split()) c ncount = min(res, b) min(res, b) ncount m = map(int, input().split()) map(int, input().split()) m res -= ncount ncount res c, b = cbl.pop() cbl.pop() c cbl = sorted(cb.items()) sorted(cb.items()) cbl ans = 0 0 ans ans += c * ncount c * ncount ans res = n n res
n, m = map(int, input().split())

from collections import defaultdict

cb = defaultdict(int)

for a in input().split():
    cb[int(a)] += 1

for _ in range(m):
    b, c = map(int, input().split())
    cb[c] += b

cbl = sorted(cb.items())

res = n

ans = 0

while res > 0:
    c, b = cbl.pop()
    ncount = min(res, b)
    ans += c * ncount
    res -= ncount

print(ans)