import heapq
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))
d = defaultdict(int)
hq = []
heapq.heapify(hq)
for i in range(N):
    d[A[i]] += 1

for key, value in d.items():
    heapq.heappush(hq, (-key, value))

for i in range(M):
    b, c = map(int, input().split())
    heapq.heappush(hq, (-c, b))

ans = 0
for i in range(N):
    number, cnt = heapq.heappop(hq)
    ans += number
    if cnt > 1:
        heapq.heappush(hq, (number, cnt-1))

print(-ans)
 import heapq heapq 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(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split d = defaultdict(int) d defaultdict(int) defaultdict int hq = [] hq [] heapq.heapify(hq) heapq.heapify heapq heapify hq for i in range(N):
    d[A[i]] += 1 i range(N) range N d[A[i]] += 1 d[A[i]] d A[i] A i 1 for key, value in d.items():
    heapq.heappush(hq, (-key, value)) key value d.items() d.items d items heapq.heappush(hq, (-key, value)) heapq.heappush heapq heappush hq (-key, value) -key key value for i in range(M):
    b, c = map(int, input().split())
    heapq.heappush(hq, (-c, 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 heapq.heappush(hq, (-c, b)) heapq.heappush heapq heappush hq (-c, b) -c c b ans = 0 ans 0 for i in range(N):
    number, cnt = heapq.heappop(hq)
    ans += number
    if cnt > 1:
        heapq.heappush(hq, (number, cnt-1)) i range(N) range N number, cnt = heapq.heappop(hq) number heapq.heappop(hq) heapq.heappop heapq heappop hq cnt ans += number ans number if cnt > 1:
        heapq.heappush(hq, (number, cnt-1)) cnt > 1 cnt 1 heapq.heappush(hq, (number, cnt-1)) heapq.heappush heapq heappush hq (number, cnt-1) number cnt-1 cnt 1 print(-ans) print -ans ans N, M = map(int, input().split()) map(int, input().split()) N ans = 0 0 ans d = defaultdict(int) defaultdict(int) d hq = [] [] hq M = map(int, input().split()) map(int, input().split()) M A = list(map(int, input().split())) list(map(int, input().split())) A number, cnt = heapq.heappop(hq) heapq.heappop(hq) number cnt = heapq.heappop(hq) heapq.heappop(hq) cnt ans += number number ans b, c = map(int, input().split()) map(int, input().split()) b c = map(int, input().split()) map(int, input().split()) c
import heapq
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))
d = defaultdict(int)
hq = []
heapq.heapify(hq)
for i in range(N):
    d[A[i]] += 1

for key, value in d.items():
    heapq.heappush(hq, (-key, value))

for i in range(M):
    b, c = map(int, input().split())
    heapq.heappush(hq, (-c, b))

ans = 0
for i in range(N):
    number, cnt = heapq.heappop(hq)
    ans += number
    if cnt > 1:
        heapq.heappush(hq, (number, cnt-1))

print(-ans)

