N, M = map(int, input().split())
d = dict()
A = list(map(int, input().split()))
for i in range(N):
	d[A[i]] = d.get(A[i], 0) + 1
for i in range(M):
	B, C = map(int, input().split())
	d[C] = d.get(C, 0) + B

ans = 0
keys = sorted(list(d.keys()), reverse = True)
for k in keys:
	kosuu = min(N, d.get(k))
	ans += k * kosuu
	N -= kosuu
	if N == 0:
		break
print(ans) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M d = dict() d dict() dict A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for i in range(N):
	d[A[i]] = d.get(A[i], 0) + 1 i range(N) range N d[A[i]] = d.get(A[i], 0) + 1 d[A[i]] d A[i] A i d.get(A[i], 0) + 1 d.get(A[i], 0) d.get d get A[i] A i 0 1 for i in range(M):
	B, C = map(int, input().split())
	d[C] = d.get(C, 0) + B i range(M) range M B, C = map(int, input().split()) B map(int, input().split()) map int input().split() ().split () input split C d[C] = d.get(C, 0) + B d[C] d C d.get(C, 0) + B d.get(C, 0) d.get d get C 0 B ans = 0 ans 0 keys = sorted(list(d.keys()), reverse = True) keys sorted(list(d.keys()), reverse = True) sorted list(d.keys()) list d.keys() d.keys d keys reverse = True reverse True for k in keys:
	kosuu = min(N, d.get(k))
	ans += k * kosuu
	N -= kosuu
	if N == 0:
		break k keys kosuu = min(N, d.get(k)) kosuu min(N, d.get(k)) min N d.get(k) d.get d get k ans += k * kosuu ans k * kosuu k kosuu N -= kosuu N kosuu if N == 0:
		break N == 0 N 0 break print(ans) print ans M = map(int, input().split()) map(int, input().split()) M d = dict() dict() d A = list(map(int, input().split())) list(map(int, input().split())) A C = map(int, input().split()) map(int, input().split()) C N -= kosuu kosuu N keys = sorted(list(d.keys()), reverse = True) sorted(list(d.keys()), reverse = True) keys B, C = map(int, input().split()) map(int, input().split()) B kosuu = min(N, d.get(k)) min(N, d.get(k)) kosuu ans = 0 0 ans ans += k * kosuu k * kosuu ans N, M = map(int, input().split()) map(int, input().split()) N
N, M = map(int, input().split())
d = dict()
A = list(map(int, input().split()))
for i in range(N):
	d[A[i]] = d.get(A[i], 0) + 1
for i in range(M):
	B, C = map(int, input().split())
	d[C] = d.get(C, 0) + B

ans = 0
keys = sorted(list(d.keys()), reverse = True)
for k in keys:
	kosuu = min(N, d.get(k))
	ans += k * kosuu
	N -= kosuu
	if N == 0:
		break
print(ans)