import math
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
c = sorted(c.items(), reverse=True)
s = 0
for i in c:
    s += i[0] * min(i[1],N)
    N -= min(i[1],N)
print(s) import math math 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 c = sorted(c.items(), reverse=True) c sorted(c.items(), reverse=True) sorted c.items() c.items c items reverse=True reverse True s = 0 s 0 for i in c:
    s += i[0] * min(i[1],N)
    N -= min(i[1],N) i c s += i[0] * min(i[1],N) s i[0] * min(i[1],N) i[0] i 0 min(i[1],N) min i[1] i 1 N N -= min(i[1],N) N min(i[1],N) min i[1] i 1 N print(s) print s s = 0 0 s c = Counter(map(int, input().split())) Counter(map(int, input().split())) c c = sorted(c.items(), reverse=True) sorted(c.items(), reverse=True) c N -= min(i[1],N) min(i[1],N) N C = map(int, input().split()) map(int, input().split()) C M = map(int, input().split()) map(int, input().split()) M s += i[0] * min(i[1],N) i[0] * min(i[1],N) s N, M = map(int, input().split()) map(int, input().split()) N B, C = map(int, input().split()) map(int, input().split()) B
import math
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
c = sorted(c.items(), reverse=True)
s = 0
for i in c:
    s += i[0] * min(i[1],N)
    N -= min(i[1],N)
print(s)
