import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import Counter
import heapq

N, M = map(int, input().split())

A = list(map(int, input().split()))

counter_A = Counter(A)

lis = []
for v,c in counter_A.items():
    heapq.heappush(lis, (-v, c))

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

cnt = 0
ans = 0    

while cnt <= N:
    v, c = heapq.heappop(lis)
    v *= -1

    if cnt + c > N:
        ans += v*(N-cnt)
        break
    else:
        ans += v*c
        cnt += c
print(ans)  import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip 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 = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split counter_A = Counter(A) counter_A Counter(A) Counter A lis = [] lis [] for v,c in counter_A.items():
    heapq.heappush(lis, (-v, c)) v c counter_A.items() counter_A.items counter_A items heapq.heappush(lis, (-v, c)) heapq.heappush heapq heappush lis (-v, c) -v v c for i in range(M):
    b, c = map(int, input().split())
    heapq.heappush(lis, (-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(lis, (-c, b)) heapq.heappush heapq heappush lis (-c, b) -c c b cnt = 0 cnt 0 ans = 0 ans 0 while cnt <= N:
    v, c = heapq.heappop(lis)
    v *= -1

    if cnt + c > N:
        ans += v*(N-cnt)
        break
    else:
        ans += v*c
        cnt += c cnt <= N cnt N v, c = heapq.heappop(lis) v heapq.heappop(lis) heapq.heappop heapq heappop lis c v *= -1 v -1 if cnt + c > N:
        ans += v*(N-cnt)
        break
    else:
        ans += v*c
        cnt += c cnt + c > N cnt + c cnt c N ans += v*(N-cnt) ans v*(N-cnt) v N-cnt N cnt break ans += v*c ans v*c v c cnt += c cnt c print(ans) print ans ans = 0 0 ans input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input b, c = map(int, input().split()) map(int, input().split()) b lis = [] [] lis ans += v*(N-cnt) v*(N-cnt) ans ans += v*c v*c ans N, M = map(int, input().split()) map(int, input().split()) N c = map(int, input().split()) map(int, input().split()) c counter_A = Counter(A) Counter(A) counter_A c = heapq.heappop(lis) heapq.heappop(lis) c v, c = heapq.heappop(lis) heapq.heappop(lis) v v *= -1 -1 v cnt = 0 0 cnt A = list(map(int, input().split())) list(map(int, input().split())) A M = map(int, input().split()) map(int, input().split()) M cnt += c c cnt
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import Counter
import heapq

N, M = map(int, input().split())

A = list(map(int, input().split()))

counter_A = Counter(A)

lis = []
for v,c in counter_A.items():
    heapq.heappush(lis, (-v, c))

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

cnt = 0
ans = 0    

while cnt <= N:
    v, c = heapq.heappop(lis)
    v *= -1

    if cnt + c > N:
        ans += v*(N-cnt)
        break
    else:
        ans += v*c
        cnt += c
print(ans) 