N, M = map(int, input().split())
from collections import*
c = Counter(map(int, input().split()))
for _ in range(M):
    B, C = map(int, input().split())
    c[C] = c[C] + B if C in c else B
s = 0
for i in sorted(c.items())[::-1]:
    m = min(i[1], N)
    s += i[0] * m
    N -= m
print(s) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M from collections import* c = Counter(map(int, input().split())) c Counter(map(int, input().split())) Counter map(int, input().split()) map int input().split() ().split () input split for _ in range(M):
    B, C = map(int, input().split())
    c[C] = c[C] + B if C in c else B _ range(M) range M B, C = map(int, input().split()) B map(int, input().split()) map int input().split() ().split () input split C c[C] = c[C] + B if C in c else B c[C] c C c[C] + B if C in c else B C in c C c c[C] + B c[C] c C B B s = 0 s 0 for i in sorted(c.items())[::-1]:
    m = min(i[1], N)
    s += i[0] * m
    N -= m i sorted(c.items())[::-1] (c.items()) sorted c.items() c.items c items ::-1 -1 m = min(i[1], N) m min(i[1], N) min i[1] i 1 N s += i[0] * m s i[0] * m i[0] i 0 m N -= m N m print(s) print s m = min(i[1], N) min(i[1], N) m C = map(int, input().split()) map(int, input().split()) C s += i[0] * m i[0] * m s M = map(int, input().split()) map(int, input().split()) M c = Counter(map(int, input().split())) Counter(map(int, input().split())) c N -= m m N N, M = map(int, input().split()) map(int, input().split()) N B, C = map(int, input().split()) map(int, input().split()) B s = 0 0 s
N, M = map(int, input().split())
from collections import*
c = Counter(map(int, input().split()))
for _ in range(M):
    B, C = map(int, input().split())
    c[C] = c[C] + B if C in c else B
s = 0
for i in sorted(c.items())[::-1]:
    m = min(i[1], N)
    s += i[0] * m
    N -= m
print(s)
