from collections import defaultdict
dic = defaultdict(int)
N,M = map(int,input().split())
A = list(map(int,input().split()))
for x in A:
  dic[x] += 1
for i in range(M):
  a,b = map(int,input().split())
  dic[b] += a

#print(dic)
L =list(dic.keys())
L.sort(reverse = True)

cnt = 0
ans = 0
for i in range(len(L)):
  val = L[i]
  #print(cnt,val,dic[val])
  if cnt + dic[val] <= N:
    cnt += dic[val]
    ans += val*dic[val]
  else:
    ans += val*(N-cnt)
    break
print(ans) from collections import defaultdict dic = defaultdict(int) dic defaultdict(int) defaultdict int 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 for x in A:
  dic[x] += 1 x A dic[x] += 1 dic[x] dic x 1 for i in range(M):
  a,b = map(int,input().split())
  dic[b] += a

#print(dic) i range(M) range M a,b = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b dic[b] += a dic[b] dic b a L =list(dic.keys()) L list(dic.keys()) list dic.keys() dic.keys dic keys L.sort(reverse = True) L.sort L sort reverse = True reverse True cnt = 0 cnt 0 ans = 0 ans 0 for i in range(len(L)):
  val = L[i]
  #print(cnt,val,dic[val])
  if cnt + dic[val] <= N:
    cnt += dic[val]
    ans += val*dic[val]
  else:
    ans += val*(N-cnt)
    break i range(len(L)) range len(L) len L val = L[i] val L[i] L i if cnt + dic[val] <= N:
    cnt += dic[val]
    ans += val*dic[val]
  else:
    ans += val*(N-cnt)
    break cnt + dic[val] <= N cnt + dic[val] cnt dic[val] dic val N cnt += dic[val] cnt dic[val] dic val ans += val*dic[val] ans val*dic[val] val dic[val] dic val ans += val*(N-cnt) ans val*(N-cnt) val N-cnt N cnt break print(ans) print ans ans = 0 0 ans ans += val*dic[val] val*dic[val] ans b = map(int,input().split()) map(int,input().split()) b N,M = map(int,input().split()) map(int,input().split()) N ans += val*(N-cnt) val*(N-cnt) ans M = map(int,input().split()) map(int,input().split()) M a,b = map(int,input().split()) map(int,input().split()) a val = L[i] L[i] val L =list(dic.keys()) list(dic.keys()) L cnt = 0 0 cnt A = list(map(int,input().split())) list(map(int,input().split())) A dic = defaultdict(int) defaultdict(int) dic cnt += dic[val] dic[val] cnt
from collections import defaultdict
dic = defaultdict(int)
N,M = map(int,input().split())
A = list(map(int,input().split()))
for x in A:
  dic[x] += 1
for i in range(M):
  a,b = map(int,input().split())
  dic[b] += a

#print(dic)
L =list(dic.keys())
L.sort(reverse = True)

cnt = 0
ans = 0
for i in range(len(L)):
  val = L[i]
  #print(cnt,val,dic[val])
  if cnt + dic[val] <= N:
    cnt += dic[val]
    ans += val*dic[val]
  else:
    ans += val*(N-cnt)
    break
print(ans)
