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

D = dict(Counter(A))  #Aの要素の個数を数える。
for i in range(M):
    B,C = list(map(int,input().split()))
    D[C] = D.get(C,0) + B  #DのCがBあるっていう情報追加
# print(D)

K = sorted(list(D.keys()),reverse=True)  #Dのkeyを降順にソート
# print(K)

out = 0
cnt = 0 #N回で終了
now = 0
while cnt<=N-1:
    if D[K[now]] > 0: #大きい順に、D[K[now]]かい繰り返す
        out += K[now]
        D[K[now]] -= 1
        cnt+=1
    else:
        now+=1
print(out) from collections import Counter [N,M] = list(map(int,input().split())) [N,M] N M list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split 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 = dict(Counter(A)) D dict(Counter(A)) dict Counter(A) Counter A for i in range(M):
    B,C = list(map(int,input().split()))
    D[C] = D.get(C,0) + B  #DのCがBあるっていう情報追加
# print(D) i range(M) range M B,C = list(map(int,input().split())) B list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split C D[C] = D.get(C,0) + B D[C] D C D.get(C,0) + B D.get(C,0) D.get D get C 0 B K = sorted(list(D.keys()),reverse=True) K sorted(list(D.keys()),reverse=True) sorted list(D.keys()) list D.keys() D.keys D keys reverse=True reverse True out = 0 out 0 cnt = 0 cnt 0 now = 0 now 0 while cnt<=N-1:
    if D[K[now]] > 0: #大きい順に、D[K[now]]かい繰り返す
        out += K[now]
        D[K[now]] -= 1
        cnt+=1
    else:
        now+=1 cnt<=N-1 cnt N-1 N 1 if D[K[now]] > 0: #大きい順に、D[K[now]]かい繰り返す
        out += K[now]
        D[K[now]] -= 1
        cnt+=1
    else:
        now+=1 D[K[now]] > 0 D[K[now]] D K[now] K now 0 out += K[now] out K[now] K now D[K[now]] -= 1 D[K[now]] D K[now] K now 1 cnt+=1 cnt 1 now+=1 now 1 print(out) print out B,C = list(map(int,input().split())) list(map(int,input().split())) B cnt+=1 1 cnt A = list(map(int,input().split())) list(map(int,input().split())) A cnt = 0 0 cnt K = sorted(list(D.keys()),reverse=True) sorted(list(D.keys()),reverse=True) K now = 0 0 now now+=1 1 now out += K[now] K[now] out out = 0 0 out D = dict(Counter(A)) dict(Counter(A)) D C = list(map(int,input().split())) list(map(int,input().split())) C
from collections import Counter
[N,M] = list(map(int,input().split()))
A = list(map(int,input().split()))

D = dict(Counter(A))  #Aの要素の個数を数える。
for i in range(M):
    B,C = list(map(int,input().split()))
    D[C] = D.get(C,0) + B  #DのCがBあるっていう情報追加
# print(D)

K = sorted(list(D.keys()),reverse=True)  #Dのkeyを降順にソート
# print(K)

out = 0
cnt = 0 #N回で終了
now = 0
while cnt<=N-1:
    if D[K[now]] > 0: #大きい順に、D[K[now]]かい繰り返す
        out += K[now]
        D[K[now]] -= 1
        cnt+=1
    else:
        now+=1
print(out)