from collections import Counter


N, M = [int(x) for x in input().split()]
Cnter = Counter([int(x) for x in input().split()])
for i in range(M):
    b, c = [int(x) for x in input().split()]
    Cnter[c] += b
V = sorted(list(Cnter.most_common()))
cnt = 0
ans = 0
for v in V[::-1]:
    ans += v[0] * min(v[1], N - cnt)
    cnt += v[1]
    if cnt >= N:
        break
print(ans) from collections import Counter int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x N, M = [int(x) for x in input().split()] N [int(x) for x in input().split()] M int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x Cnter = Counter([int(x) for x in input().split()]) Cnter Counter([int(x) for x in input().split()]) Counter [int(x) for x in input().split()] for i in range(M):
    b, c = [int(x) for x in input().split()]
    Cnter[c] += b i range(M) range M int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x b, c = [int(x) for x in input().split()] b [int(x) for x in input().split()] c Cnter[c] += b Cnter[c] Cnter c b V = sorted(list(Cnter.most_common())) V sorted(list(Cnter.most_common())) sorted list(Cnter.most_common()) list Cnter.most_common() Cnter.most_common Cnter most_common cnt = 0 cnt 0 ans = 0 ans 0 for v in V[::-1]:
    ans += v[0] * min(v[1], N - cnt)
    cnt += v[1]
    if cnt >= N:
        break v V[::-1] V ::-1 -1 ans += v[0] * min(v[1], N - cnt) ans v[0] * min(v[1], N - cnt) v[0] v 0 min(v[1], N - cnt) min v[1] v 1 N - cnt N cnt cnt += v[1] cnt v[1] v 1 if cnt >= N:
        break cnt >= N cnt N break print(ans) print ans b, c = [int(x) for x in input().split()] [int(x) for x in input().split()] b N, M = [int(x) for x in input().split()] [int(x) for x in input().split()] N M = [int(x) for x in input().split()] [int(x) for x in input().split()] M Cnter = Counter([int(x) for x in input().split()]) Counter([int(x) for x in input().split()]) Cnter V = sorted(list(Cnter.most_common())) sorted(list(Cnter.most_common())) V ans = 0 0 ans c = [int(x) for x in input().split()] [int(x) for x in input().split()] c cnt += v[1] v[1] cnt cnt = 0 0 cnt ans += v[0] * min(v[1], N - cnt) v[0] * min(v[1], N - cnt) ans
from collections import Counter


N, M = [int(x) for x in input().split()]
Cnter = Counter([int(x) for x in input().split()])
for i in range(M):
    b, c = [int(x) for x in input().split()]
    Cnter[c] += b
V = sorted(list(Cnter.most_common()))
cnt = 0
ans = 0
for v in V[::-1]:
    ans += v[0] * min(v[1], N - cnt)
    cnt += v[1]
    if cnt >= N:
        break
print(ans)
