from itertools import accumulate

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for _ in range(M)]

A = sorted(A)
BC = sorted(BC, key = lambda x: x[1], reverse=True)

trade = []
len_ = 0
for b, c in BC:
    if len_ >= N:
        break
    for _ in range(b):
        if len_ >= N:
            break
        trade.append(c)
        len_ += 1

ans = 0
for i in range(N):
    if i >= len_:
        ans += A[i]
    else:
        ans += max(trade[i], A[i])
print(ans) from itertools import accumulate 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 tuple(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split BC = [tuple(map(int, input().split())) for _ in range(M)] BC [tuple(map(int, input().split())) for _ in range(M)] A = sorted(A) A sorted(A) sorted A BC = sorted(BC, key = lambda x: x[1], reverse=True) BC sorted(BC, key = lambda x: x[1], reverse=True) sorted BC key = lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True trade = [] trade [] len_ = 0 len_ 0 for b, c in BC:
    if len_ >= N:
        break
    for _ in range(b):
        if len_ >= N:
            break
        trade.append(c)
        len_ += 1 b c BC if len_ >= N:
        break
     len_ >= N len_ N break for _ in range(b):
        if len_ >= N:
            break
        trade.append(c)
        len_ += 1 _ range(b) range b if len_ >= N:
            break
         len_ >= N len_ N break trade.append(c) trade.append trade append c len_ += 1 len_ 1 ans = 0 ans 0 for i in range(N):
    if i >= len_:
        ans += A[i]
    else:
        ans += max(trade[i], A[i]) i range(N) range N if i >= len_:
        ans += A[i]
    else:
        ans += max(trade[i], A[i]) i >= len_ i len_ ans += A[i] ans A[i] A i ans += max(trade[i], A[i]) ans max(trade[i], A[i]) max trade[i] trade i A[i] A i print(ans) print ans BC = sorted(BC, key = lambda x: x[1], reverse=True) sorted(BC, key = lambda x: x[1], reverse=True) BC len_ += 1 1 len_ ans = 0 0 ans len_ = 0 0 len_ ans += A[i] A[i] ans BC = [tuple(map(int, input().split())) for _ in range(M)] [tuple(map(int, input().split())) for _ in range(M)] BC trade = [] [] trade ans += max(trade[i], A[i]) max(trade[i], A[i]) ans A = list(map(int, input().split())) list(map(int, input().split())) A M = map(int, input().split()) map(int, input().split()) M A = sorted(A) sorted(A) A N, M = map(int, input().split()) map(int, input().split()) N
from itertools import accumulate

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for _ in range(M)]

A = sorted(A)
BC = sorted(BC, key = lambda x: x[1], reverse=True)

trade = []
len_ = 0
for b, c in BC:
    if len_ >= N:
        break
    for _ in range(b):
        if len_ >= N:
            break
        trade.append(c)
        len_ += 1

ans = 0
for i in range(N):
    if i >= len_:
        ans += A[i]
    else:
        ans += max(trade[i], A[i])
print(ans)
