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

cnt = {}

for i in range(n):
    if a[i] in cnt:
        cnt[a[i]] += 1
    else:
        cnt[a[i]] = 1

for i in range(m):
    b, c = list(map(int, input().split()))

    if c in cnt:
        cnt[c] += b
    else:
        cnt[c] = b

cnts = sorted(cnt.items())
cnt = 0
tot = 0
last = (0, 0)

while cnt < n:
    last = cnts.pop()
    tot += last[0] * last[1]
    cnt += last[1]

tot -= (cnt-n)*last[0]
print(tot) n, m = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split m a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cnt = {} cnt {} for i in range(n):
    if a[i] in cnt:
        cnt[a[i]] += 1
    else:
        cnt[a[i]] = 1 i range(n) range n if a[i] in cnt:
        cnt[a[i]] += 1
    else:
        cnt[a[i]] = 1 a[i] in cnt a[i] a i cnt cnt[a[i]] += 1 cnt[a[i]] cnt a[i] a i 1 cnt[a[i]] = 1 cnt[a[i]] cnt a[i] a i 1 for i in range(m):
    b, c = list(map(int, input().split()))

    if c in cnt:
        cnt[c] += b
    else:
        cnt[c] = b i range(m) range m b, c = list(map(int, input().split())) b list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split c if c in cnt:
        cnt[c] += b
    else:
        cnt[c] = b c in cnt c cnt cnt[c] += b cnt[c] cnt c b cnt[c] = b cnt[c] cnt c b cnts = sorted(cnt.items()) cnts sorted(cnt.items()) sorted cnt.items() cnt.items cnt items cnt = 0 cnt 0 tot = 0 tot 0 last = (0, 0) last (0, 0) 0 0 while cnt < n:
    last = cnts.pop()
    tot += last[0] * last[1]
    cnt += last[1] cnt < n cnt n last = cnts.pop() last cnts.pop() cnts.pop cnts pop tot += last[0] * last[1] tot last[0] * last[1] last[0] last 0 last[1] last 1 cnt += last[1] cnt last[1] last 1 tot -= (cnt-n)*last[0] tot (cnt-n)*last[0] cnt-n cnt n last[0] last 0 print(tot) print tot tot += last[0] * last[1] last[0] * last[1] tot tot = 0 0 tot c = list(map(int, input().split())) list(map(int, input().split())) c m = list(map(int, input().split())) list(map(int, input().split())) m cnt = {} {} cnt cnt = 0 0 cnt last = (0, 0) (0, 0) last a = list(map(int, input().split())) list(map(int, input().split())) a n, m = list(map(int, input().split())) list(map(int, input().split())) n b, c = list(map(int, input().split())) list(map(int, input().split())) b cnts = sorted(cnt.items()) sorted(cnt.items()) cnts last = cnts.pop() cnts.pop() last cnt += last[1] last[1] cnt tot -= (cnt-n)*last[0] (cnt-n)*last[0] tot
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

cnt = {}

for i in range(n):
    if a[i] in cnt:
        cnt[a[i]] += 1
    else:
        cnt[a[i]] = 1

for i in range(m):
    b, c = list(map(int, input().split()))

    if c in cnt:
        cnt[c] += b
    else:
        cnt[c] = b

cnts = sorted(cnt.items())
cnt = 0
tot = 0
last = (0, 0)

while cnt < n:
    last = cnts.pop()
    tot += last[0] * last[1]
    cnt += last[1]

tot -= (cnt-n)*last[0]
print(tot)