from collections import Counter

N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

BC = [tuple([int(_) for _ in input().split()]) for _ in range(M)]

X = Counter(A)
for a in X:
    BC.append((X[a], a))
BC.sort(key=lambda x: x[1], reverse=True)

ans = 0
k = N
for b, c in BC:
    v = min(k, b)
    ans += v * c
    k -= v

print(ans) from collections import Counter int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ N, M = [int(_) for _ in input().split()] N [int(_) for _ in input().split()] M int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ A = [int(_) for _ in input().split()] A [int(_) for _ in input().split()] tuple([int(_) for _ in input().split()]) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) tuple([int(_) for _ in input().split()]) tuple [int(_) for _ in input().split()] BC = [tuple([int(_) for _ in input().split()]) for _ in range(M)] BC [tuple([int(_) for _ in input().split()]) for _ in range(M)] X = Counter(A) X Counter(A) Counter A for a in X:
    BC.append((X[a], a)) a X BC.append((X[a], a)) BC.append BC append (X[a], a) X[a] X a a BC.sort(key=lambda x: x[1], reverse=True) BC.sort BC sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True ans = 0 ans 0 k = N k N for b, c in BC:
    v = min(k, b)
    ans += v * c
    k -= v b c BC v = min(k, b) v min(k, b) min k b ans += v * c ans v * c v c k -= v k v print(ans) print ans X = Counter(A) Counter(A) X k = N N k k -= v v k N, M = [int(_) for _ in input().split()] [int(_) for _ in input().split()] N v = min(k, b) min(k, b) v ans += v * c v * c ans M = [int(_) for _ in input().split()] [int(_) for _ in input().split()] M A = [int(_) for _ in input().split()] [int(_) for _ in input().split()] A BC = [tuple([int(_) for _ in input().split()]) for _ in range(M)] [tuple([int(_) for _ in input().split()]) for _ in range(M)] BC ans = 0 0 ans
from collections import Counter

N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

BC = [tuple([int(_) for _ in input().split()]) for _ in range(M)]

X = Counter(A)
for a in X:
    BC.append((X[a], a))
BC.sort(key=lambda x: x[1], reverse=True)

ans = 0
k = N
for b, c in BC:
    v = min(k, b)
    ans += v * c
    k -= v

print(ans)
