from collections import defaultdict
from collections import Counter

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

d = defaultdict(int)
c = Counter(arr)

for k, v in c.items():
    d[k] += v

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

d = list(d.items())
d.sort(key=lambda x: x[0], reverse=True)

ans = 0
for k, v in d:
    ans += k * min(n, v)
    if n > v:
        n -= v
    else:
        break

print(ans) from collections import defaultdict from collections import Counter n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m arr = list(map(int, input().split())) arr list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split d = defaultdict(int) d defaultdict(int) defaultdict int c = Counter(arr) c Counter(arr) Counter arr for k, v in c.items():
    d[k] += v k v c.items() c.items c items d[k] += v d[k] d k v for _ in range(m):
    b, c = map(int, input().split())
    d[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 d[c] += b d[c] d c b d = list(d.items()) d list(d.items()) list d.items() d.items d items d.sort(key=lambda x: x[0], reverse=True) d.sort d sort key=lambda x: x[0] key lambda x: x[0] x[0] x 0 x reverse=True reverse True ans = 0 ans 0 for k, v in d:
    ans += k * min(n, v)
    if n > v:
        n -= v
    else:
        break k v d ans += k * min(n, v) ans k * min(n, v) k min(n, v) min n v if n > v:
        n -= v
    else:
        break n > v n v n -= v n v break print(ans) print ans m = map(int, input().split()) map(int, input().split()) m d = list(d.items()) list(d.items()) d ans = 0 0 ans ans += k * min(n, v) k * min(n, v) ans arr = list(map(int, input().split())) list(map(int, input().split())) arr c = map(int, input().split()) map(int, input().split()) c d = defaultdict(int) defaultdict(int) d c = Counter(arr) Counter(arr) c n -= v v n n, m = map(int, input().split()) map(int, input().split()) n b, c = map(int, input().split()) map(int, input().split()) b
from collections import defaultdict
from collections import Counter

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

d = defaultdict(int)
c = Counter(arr)

for k, v in c.items():
    d[k] += v

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

d = list(d.items())
d.sort(key=lambda x: x[0], reverse=True)

ans = 0
for k, v in d:
    ans += k * min(n, v)
    if n > v:
        n -= v
    else:
        break

print(ans)