from collections import Counter

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]

num, seta = Counter(a), set(a)
for b, c in bc:
    num[c] += b
    seta.add(c)
sorta = sorted(list(seta), reverse=True)
cnt, ans = n, 0
for i in sorta:
    ans += i * min(num[i], cnt)
    cnt -= num[i]
    if cnt <= 0:
        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 = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bc = [list(map(int, input().split())) for _ in range(m)] bc [list(map(int, input().split())) for _ in range(m)] num, seta = Counter(a), set(a) num Counter(a) Counter a seta set(a) set a for b, c in bc:
    num[c] += b
    seta.add(c) b c bc num[c] += b num[c] num c b seta.add(c) seta.add seta add c sorta = sorted(list(seta), reverse=True) sorta sorted(list(seta), reverse=True) sorted list(seta) list seta reverse=True reverse True cnt, ans = n, 0 cnt n ans 0 for i in sorta:
    ans += i * min(num[i], cnt)
    cnt -= num[i]
    if cnt <= 0:
        break i sorta ans += i * min(num[i], cnt) ans i * min(num[i], cnt) i min(num[i], cnt) min num[i] num i cnt cnt -= num[i] cnt num[i] num i if cnt <= 0:
        break cnt <= 0 cnt 0 break print(ans) print ans a = list(map(int, input().split())) list(map(int, input().split())) a ans = n, 0 0 ans cnt, ans = n, 0 n cnt n, m = map(int, input().split()) map(int, input().split()) n sorta = sorted(list(seta), reverse=True) sorted(list(seta), reverse=True) sorta cnt -= num[i] num[i] cnt seta = Counter(a), set(a) set(a) seta ans += i * min(num[i], cnt) i * min(num[i], cnt) ans m = map(int, input().split()) map(int, input().split()) m num, seta = Counter(a), set(a) Counter(a) num bc = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] bc
from collections import Counter

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]

num, seta = Counter(a), set(a)
for b, c in bc:
    num[c] += b
    seta.add(c)
sorta = sorted(list(seta), reverse=True)
cnt, ans = n, 0
for i in sorta:
    ans += i * min(num[i], cnt)
    cnt -= num[i]
    if cnt <= 0:
        break
print(ans)
