from collections import defaultdict

N, M = map(int, input().split())
# Aは昇順に並べる
A = list(sorted(map(int, input().split())))

# B,Cの対応辞書を作り、C順に並べる
counter = defaultdict(int)
for _ in range(M):
    B, C = map(int, input().split())
    counter[C] += B
c_list = list(sorted(counter.keys(), reverse=True))

# Cを大きい順に個数分並べたリストを作る
moves = []
n = 0
for c in c_list:
    b = counter[c]
    if n + b < N:
        p = b
    else:
        p = N - n
    for i in range(p):
        moves.append(c)
    if len(moves) >= N:
        break

# AとCを小さい順に比較
siz = min(N, len(moves))
for i in range(siz):
    # Aの小さいものを上書き
    A[i] = max(A[i], moves[i])

print(sum(A)) from collections import defaultdict N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = list(sorted(map(int, input().split()))) A list(sorted(map(int, input().split()))) list sorted(map(int, input().split())) sorted map(int, input().split()) map int input().split() ().split () input split counter = defaultdict(int) counter defaultdict(int) defaultdict int for _ in range(M):
    B, C = map(int, input().split())
    counter[C] += B _ range(M) range M B, C = map(int, input().split()) B map(int, input().split()) map int input().split() ().split () input split C counter[C] += B counter[C] counter C B c_list = list(sorted(counter.keys(), reverse=True)) c_list list(sorted(counter.keys(), reverse=True)) list sorted(counter.keys(), reverse=True) sorted counter.keys() counter.keys counter keys reverse=True reverse True moves = [] moves [] n = 0 n 0 for c in c_list:
    b = counter[c]
    if n + b < N:
        p = b
    else:
        p = N - n
    for i in range(p):
        moves.append(c)
    if len(moves) >= N:
        break

# AとCを小さい順に比較 c c_list b = counter[c] b counter[c] counter c if n + b < N:
        p = b
    else:
        p = N - n
     n + b < N n + b n b N p = b p b p = N - n p N - n N n for i in range(p):
        moves.append(c)
     i range(p) range p moves.append(c) moves.append moves append c if len(moves) >= N:
        break

# AとCを小さい順に比較 len(moves) >= N len(moves) len moves N break siz = min(N, len(moves)) siz min(N, len(moves)) min N len(moves) len moves for i in range(siz):
    # Aの小さいものを上書き
    A[i] = max(A[i], moves[i]) i range(siz) range siz A[i] = max(A[i], moves[i]) A[i] A i max(A[i], moves[i]) max A[i] A i moves[i] moves i print(sum(A)) print sum(A) sum A A = list(sorted(map(int, input().split()))) list(sorted(map(int, input().split()))) A n = 0 0 n counter = defaultdict(int) defaultdict(int) counter siz = min(N, len(moves)) min(N, len(moves)) siz c_list = list(sorted(counter.keys(), reverse=True)) list(sorted(counter.keys(), reverse=True)) c_list b = counter[c] counter[c] b p = b b p N, M = map(int, input().split()) map(int, input().split()) N moves = [] [] moves C = map(int, input().split()) map(int, input().split()) C p = N - n N - n p B, C = map(int, input().split()) map(int, input().split()) B M = map(int, input().split()) map(int, input().split()) M
from collections import defaultdict

N, M = map(int, input().split())
# Aは昇順に並べる
A = list(sorted(map(int, input().split())))

# B,Cの対応辞書を作り、C順に並べる
counter = defaultdict(int)
for _ in range(M):
    B, C = map(int, input().split())
    counter[C] += B
c_list = list(sorted(counter.keys(), reverse=True))

# Cを大きい順に個数分並べたリストを作る
moves = []
n = 0
for c in c_list:
    b = counter[c]
    if n + b < N:
        p = b
    else:
        p = N - n
    for i in range(p):
        moves.append(c)
    if len(moves) >= N:
        break

# AとCを小さい順に比較
siz = min(N, len(moves))
for i in range(siz):
    # Aの小さいものを上書き
    A[i] = max(A[i], moves[i])

print(sum(A))
