from collections import Counter
import heapq
N,M = map(int,input().split())
A = Counter(list(map(int,input().split())))

cards = []
for x,y in A.items():
  heapq.heappush(cards, (-x,y))

for _ in range(M):
  b,c = map(int,input().split())
  heapq.heappush(cards, (-c,b))
cnt = N
ans = 0
while cnt <= N:
  v,c = heapq.heappop(cards)
  v *= -1
  if cnt-c < 0:
    ans += v*cnt
    break
  else:
    ans += v*c
    cnt -= c

print(ans) from collections import Counter import heapq heapq N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M A = Counter(list(map(int,input().split()))) A Counter(list(map(int,input().split()))) Counter list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split cards = [] cards [] for x,y in A.items():
  heapq.heappush(cards, (-x,y)) x y A.items() A.items A items heapq.heappush(cards, (-x,y)) heapq.heappush heapq heappush cards (-x,y) -x x y for _ in range(M):
  b,c = map(int,input().split())
  heapq.heappush(cards, (-c,b)) _ 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(cards, (-c,b)) heapq.heappush heapq heappush cards (-c,b) -c c b cnt = N cnt N ans = 0 ans 0 while cnt <= N:
  v,c = heapq.heappop(cards)
  v *= -1
  if cnt-c < 0:
    ans += v*cnt
    break
  else:
    ans += v*c
    cnt -= c cnt <= N cnt N v,c = heapq.heappop(cards) v heapq.heappop(cards) heapq.heappop heapq heappop cards c v *= -1 v -1 if cnt-c < 0:
    ans += v*cnt
    break
  else:
    ans += v*c
    cnt -= c cnt-c < 0 cnt-c cnt c 0 ans += v*cnt ans v*cnt v cnt break ans += v*c ans v*c v c cnt -= c cnt c print(ans) print ans v *= -1 -1 v ans += v*c v*c ans cnt = N N cnt M = map(int,input().split()) map(int,input().split()) M v,c = heapq.heappop(cards) heapq.heappop(cards) v c = heapq.heappop(cards) heapq.heappop(cards) c A = Counter(list(map(int,input().split()))) Counter(list(map(int,input().split()))) A N,M = map(int,input().split()) map(int,input().split()) N ans += v*cnt v*cnt ans c = map(int,input().split()) map(int,input().split()) c cnt -= c c cnt b,c = map(int,input().split()) map(int,input().split()) b ans = 0 0 ans cards = [] [] cards
from collections import Counter
import heapq
N,M = map(int,input().split())
A = Counter(list(map(int,input().split())))

cards = []
for x,y in A.items():
  heapq.heappush(cards, (-x,y))

for _ in range(M):
  b,c = map(int,input().split())
  heapq.heappush(cards, (-c,b))
cnt = N
ans = 0
while cnt <= N:
  v,c = heapq.heappop(cards)
  v *= -1
  if cnt-c < 0:
    ans += v*cnt
    break
  else:
    ans += v*c
    cnt -= c

print(ans)
