import heapq

N,M = map(int,input().split())
b = list(map(int,input().split()))
a = []

for i in range(N):
	a.append((b[i],1))

for i in range(M):
	bb,cc = map(int,input().split())
	a.append((cc,bb))

a.sort()
a.reverse()

#for j in a:
#	print(j)

cnt = 0
ans = 0

for i in range(N):
	if cnt + a[i][1] > N:
		ans += a[i][0]*(N-cnt)
		break

	ans += a[i][0]*a[i][1]
	cnt += a[i][1]

print(ans) import heapq heapq N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M b = list(map(int,input().split())) b list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split a = [] a [] for i in range(N):
	a.append((b[i],1)) i range(N) range N a.append((b[i],1)) a.append a append (b[i],1) b[i] b i 1 for i in range(M):
	bb,cc = map(int,input().split())
	a.append((cc,bb)) i range(M) range M bb,cc = map(int,input().split()) bb map(int,input().split()) map int input().split() ().split () input split cc a.append((cc,bb)) a.append a append (cc,bb) cc bb a.sort() a.sort a sort a.reverse() a.reverse a reverse cnt = 0 cnt 0 ans = 0 ans 0 for i in range(N):
	if cnt + a[i][1] > N:
		ans += a[i][0]*(N-cnt)
		break

	ans += a[i][0]*a[i][1]
	cnt += a[i][1] i range(N) range N if cnt + a[i][1] > N:
		ans += a[i][0]*(N-cnt)
		break

	 cnt + a[i][1] > N cnt + a[i][1] cnt a[i][1] [i] a i 1 N ans += a[i][0]*(N-cnt) ans a[i][0]*(N-cnt) a[i][0] [i] a i 0 N-cnt N cnt break ans += a[i][0]*a[i][1] ans a[i][0]*a[i][1] a[i][0] [i] a i 0 a[i][1] [i] a i 1 cnt += a[i][1] cnt a[i][1] [i] a i 1 print(ans) print ans b = list(map(int,input().split())) list(map(int,input().split())) b cnt += a[i][1] a[i][1] cnt N,M = map(int,input().split()) map(int,input().split()) N cc = map(int,input().split()) map(int,input().split()) cc cnt = 0 0 cnt a = [] [] a ans = 0 0 ans ans += a[i][0]*a[i][1] a[i][0]*a[i][1] ans ans += a[i][0]*(N-cnt) a[i][0]*(N-cnt) ans M = map(int,input().split()) map(int,input().split()) M bb,cc = map(int,input().split()) map(int,input().split()) bb
import heapq

N,M = map(int,input().split())
b = list(map(int,input().split()))
a = []

for i in range(N):
	a.append((b[i],1))

for i in range(M):
	bb,cc = map(int,input().split())
	a.append((cc,bb))

a.sort()
a.reverse()

#for j in a:
#	print(j)

cnt = 0
ans = 0

for i in range(N):
	if cnt + a[i][1] > N:
		ans += a[i][0]*(N-cnt)
		break

	ans += a[i][0]*a[i][1]
	cnt += a[i][1]

print(ans)