import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)

N, M = rl()
A = rl()
Q = []
for i in range(M):
	b, c = rl()
	Q.append((b, c))

A.sort()
Q = sorted(Q, key=lambda x: -x[1])

ans = 0
cur = 0
for b, c in Q:
	j = bisect_left(A, c)
	if j <= cur: continue
	n = min(j-cur, b)
	ans += n*c
	cur += n
if cur < N:
	ans += sum(A[cur:])
print(ans)
 import sys, math sys math from collections import defaultdict, deque, Counter from bisect import bisect_left, bisect_right from itertools import combinations, permutations, product from heapq import heappush, heappop from functools import lru_cache input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline rs = lambda: input().strip() rs lambda: input().strip() input().strip() ().strip () input strip ri = lambda: int(input()) ri lambda: int(input()) int(input()) int input() input rl = lambda: list(map(int, input().split())) rl lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split [v]*y for _ in range(x) for _ in range(x) _ range(x) range x for _ in range(x) [v]*y [v] v y mat = lambda x, y, v: [[v]*y for _ in range(x)] mat lambda x, y, v: [[v]*y for _ in range(x)] [[v]*y for _ in range(x)] x y v mat(y, z, v) for _ in range(x) for _ in range(x) _ range(x) range x for _ in range(x) mat(y, z, v) mat y z v ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)] ten lambda x, y, z, v: [mat(y, z, v) for _ in range(x)] [mat(y, z, v) for _ in range(x)] x y z v mod = 1000000007 mod 1000000007 sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 N, M = rl() N rl() rl M A = rl() A rl() rl Q = [] Q [] for i in range(M):
	b, c = rl()
	Q.append((b, c)) i range(M) range M b, c = rl() b rl() rl c Q.append((b, c)) Q.append Q append (b, c) b c A.sort() A.sort A sort Q = sorted(Q, key=lambda x: -x[1]) Q sorted(Q, key=lambda x: -x[1]) sorted Q key=lambda x: -x[1] key lambda x: -x[1] -x[1] x[1] x 1 x ans = 0 ans 0 cur = 0 cur 0 for b, c in Q:
	j = bisect_left(A, c)
	if j <= cur: continue
	n = min(j-cur, b)
	ans += n*c
	cur += n b c Q j = bisect_left(A, c) j bisect_left(A, c) bisect_left A c if j <= cur: continue
	 j <= cur j cur n = min(j-cur, b) n min(j-cur, b) min j-cur j cur b ans += n*c ans n*c n c cur += n cur n if cur < N:
	ans += sum(A[cur:]) cur < N cur N ans += sum(A[cur:]) ans sum(A[cur:]) sum A[cur:] A cur: cur print(ans) print ans j = bisect_left(A, c) bisect_left(A, c) j ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)] lambda x, y, z, v: [mat(y, z, v) for _ in range(x)] ten input = sys.stdin.readline sys.stdin.readline input mat = lambda x, y, v: [[v]*y for _ in range(x)] lambda x, y, v: [[v]*y for _ in range(x)] mat N, M = rl() rl() N ri = lambda: int(input()) lambda: int(input()) ri rl = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) rl A = rl() rl() A Q = [] [] Q ans = 0 0 ans ans += sum(A[cur:]) sum(A[cur:]) ans c = rl() rl() c Q = sorted(Q, key=lambda x: -x[1]) sorted(Q, key=lambda x: -x[1]) Q cur = 0 0 cur cur += n n cur n = min(j-cur, b) min(j-cur, b) n ans += n*c n*c ans b, c = rl() rl() b rs = lambda: input().strip() lambda: input().strip() rs mod = 1000000007 1000000007 mod M = rl() rl() M
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)

N, M = rl()
A = rl()
Q = []
for i in range(M):
	b, c = rl()
	Q.append((b, c))

A.sort()
Q = sorted(Q, key=lambda x: -x[1])

ans = 0
cur = 0
for b, c in Q:
	j = bisect_left(A, c)
	if j <= cur: continue
	n = min(j-cur, b)
	ans += n*c
	cur += n
if cur < N:
	ans += sum(A[cur:])
print(ans)

