from operator import itemgetter

n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]


BC.sort(reverse=True, key=itemgetter(1))
cnt = 0
for b, c in BC:
    if cnt + b > n:
        b = n-cnt
    for _ in range(b):
        A.append(c)
    cnt += b
    if cnt == n:
        break

A.sort(reverse=True)

print(sum(A[:n])) from operator import itemgetter n, m = map(int, input().split()) n 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 list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split BC = [list(map(int, input().split())) for _ in range(m)] BC [list(map(int, input().split())) for _ in range(m)] BC.sort(reverse=True, key=itemgetter(1)) BC.sort BC sort reverse=True reverse True key=itemgetter(1) key itemgetter(1) itemgetter 1 cnt = 0 cnt 0 for b, c in BC:
    if cnt + b > n:
        b = n-cnt
    for _ in range(b):
        A.append(c)
    cnt += b
    if cnt == n:
        break b c BC if cnt + b > n:
        b = n-cnt
     cnt + b > n cnt + b cnt b n b = n-cnt b n-cnt n cnt for _ in range(b):
        A.append(c)
     _ range(b) range b A.append(c) A.append A append c cnt += b cnt b if cnt == n:
        break cnt == n cnt n break A.sort(reverse=True) A.sort A sort reverse=True reverse True print(sum(A[:n])) print sum(A[:n]) sum A[:n] A :n n cnt = 0 0 cnt cnt += b b cnt A = list(map(int, input().split())) list(map(int, input().split())) A b = n-cnt n-cnt b n, m = map(int, input().split()) map(int, input().split()) n BC = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] BC m = map(int, input().split()) map(int, input().split()) m
from operator import itemgetter

n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]


BC.sort(reverse=True, key=itemgetter(1))
cnt = 0
for b, c in BC:
    if cnt + b > n:
        b = n-cnt
    for _ in range(b):
        A.append(c)
    cnt += b
    if cnt == n:
        break

A.sort(reverse=True)

print(sum(A[:n]))