import heapq
n,m = map(int, raw_input().split(' '))
ais = map(int, raw_input().split(' '))
ais.sort()
heap = []
for _ in range(m):
	u,v = map(int,raw_input().split(' ')) 
	heapq.heappush(heap, (-v,u))
res = 0
for j in range(n):
	
	if heap and -heap[0][0] > ais[j]:
		u,v = heapq.heappop(heap)
		v-=1
		res += -u
		if v >= 1: heapq.heappush(heap, (u,v))
	else:
		res += ais[j]
print res import heapq heapq n,m = map(int, raw_input().split(' ')) n map(int, raw_input().split(' ')) map int raw_input().split(' ') ().split () raw_input split ' ' m ais = map(int, raw_input().split(' ')) ais map(int, raw_input().split(' ')) map int raw_input().split(' ') ().split () raw_input split ' ' ais.sort() ais.sort ais sort heap = [] heap [] for _ in range(m):
	u,v = map(int,raw_input().split(' ')) 
	heapq.heappush(heap, (-v,u)) _ range(m) range m u,v = map(int,raw_input().split(' ')) u map(int,raw_input().split(' ')) map int raw_input().split(' ') ().split () raw_input split ' ' v heapq.heappush(heap, (-v,u)) heapq.heappush heapq heappush heap (-v,u) -v v u res = 0 res 0 for j in range(n):
	
	if heap and -heap[0][0] > ais[j]:
		u,v = heapq.heappop(heap)
		v-=1
		res += -u
		if v >= 1: heapq.heappush(heap, (u,v))
	else:
		res += ais[j] j range(n) range n if heap and -heap[0][0] > ais[j]:
		u,v = heapq.heappop(heap)
		v-=1
		res += -u
		if v >= 1: heapq.heappush(heap, (u,v))
	else:
		res += ais[j] heap and -heap[0][0] > ais[j] heap -heap[0][0] > ais[j] -heap[0][0] heap[0][0] [0] heap 0 0 ais[j] ais j u,v = heapq.heappop(heap) u heapq.heappop(heap) heapq.heappop heapq heappop heap v v-=1 v 1 res += -u res -u u if v >= 1: heapq.heappush(heap, (u,v))
	 v >= 1 v 1 res += ais[j] res ais[j] ais j print u,v = map(int,raw_input().split(' ')) map(int,raw_input().split(' ')) u m = map(int, raw_input().split(' ')) map(int, raw_input().split(' ')) m ais = map(int, raw_input().split(' ')) map(int, raw_input().split(' ')) ais v = map(int,raw_input().split(' ')) map(int,raw_input().split(' ')) v res += ais[j] ais[j] res v-=1 1 v u,v = heapq.heappop(heap) heapq.heappop(heap) u v = heapq.heappop(heap) heapq.heappop(heap) v res = 0 0 res res += -u -u res n,m = map(int, raw_input().split(' ')) map(int, raw_input().split(' ')) n heap = [] [] heap
import heapq
n,m = map(int, raw_input().split(' '))
ais = map(int, raw_input().split(' '))
ais.sort()
heap = []
for _ in range(m):
	u,v = map(int,raw_input().split(' ')) 
	heapq.heappush(heap, (-v,u))
res = 0
for j in range(n):
	
	if heap and -heap[0][0] > ais[j]:
		u,v = heapq.heappop(heap)
		v-=1
		res += -u
		if v >= 1: heapq.heappush(heap, (u,v))
	else:
		res += ais[j]
print res