from collections import Counter

n, m = map(int, input().split())
a = Counter(list(map(int, input().split())))
bc = [map(int, input().split()) for i in range(m)]
b = {}
ans = 0

for i, j in bc:
    if j in b:
        ref = b[j]
        b[j] = ref + i
    else:
        b[j] = i

d = Counter(a) + Counter(b)
keys = sorted(d)[::-1]

for key in keys:
    qty = d[key]
    if qty < n:
        ans += qty*key
        n -= qty
    else:
        ans += n*key
        break

print(ans) from collections import Counter n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m a = Counter(list(map(int, input().split()))) a Counter(list(map(int, input().split()))) Counter list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split map(int, input().split()) for i in range(m) for i in range(m) i range(m) range m for i in range(m) map(int, input().split()) map int input().split() ().split () input split bc = [map(int, input().split()) for i in range(m)] bc [map(int, input().split()) for i in range(m)] b = {} b {} ans = 0 ans 0 for i, j in bc:
    if j in b:
        ref = b[j]
        b[j] = ref + i
    else:
        b[j] = i i j bc if j in b:
        ref = b[j]
        b[j] = ref + i
    else:
        b[j] = i j in b j b ref = b[j] ref b[j] b j b[j] = ref + i b[j] b j ref + i ref i b[j] = i b[j] b j i d = Counter(a) + Counter(b) d Counter(a) + Counter(b) Counter(a) Counter a Counter(b) Counter b keys = sorted(d)[::-1] keys sorted(d)[::-1] (d) sorted d ::-1 -1 for key in keys:
    qty = d[key]
    if qty < n:
        ans += qty*key
        n -= qty
    else:
        ans += n*key
        break key keys qty = d[key] qty d[key] d key if qty < n:
        ans += qty*key
        n -= qty
    else:
        ans += n*key
        break qty < n qty n ans += qty*key ans qty*key qty key n -= qty n qty ans += n*key ans n*key n key break print(ans) print ans bc = [map(int, input().split()) for i in range(m)] [map(int, input().split()) for i in range(m)] bc ans += qty*key qty*key ans ans += n*key n*key ans n, m = map(int, input().split()) map(int, input().split()) n a = Counter(list(map(int, input().split()))) Counter(list(map(int, input().split()))) a ans = 0 0 ans m = map(int, input().split()) map(int, input().split()) m qty = d[key] d[key] qty n -= qty qty n ref = b[j] b[j] ref keys = sorted(d)[::-1] sorted(d)[::-1] keys b = {} {} b d = Counter(a) + Counter(b) Counter(a) + Counter(b) d
from collections import Counter

n, m = map(int, input().split())
a = Counter(list(map(int, input().split())))
bc = [map(int, input().split()) for i in range(m)]
b = {}
ans = 0

for i, j in bc:
    if j in b:
        ref = b[j]
        b[j] = ref + i
    else:
        b[j] = i

d = Counter(a) + Counter(b)
keys = sorted(d)[::-1]

for key in keys:
    qty = d[key]
    if qty < n:
        ans += qty*key
        n -= qty
    else:
        ans += n*key
        break

print(ans)