from collections import defaultdict
from bisect import bisect_left
N, M = map(int,input().split())
A = list(map(int,input().split()))
D = defaultdict(int)
for i in A:
  D[i]+=1
for _ in range(M):
  a, b = map(int,input().split())
  D[b]+=a
D_sorted = sorted(D.items(), key=lambda x:x[0], reverse = True)
ans = 0
count = 0
for x, c in D_sorted:
  if count+c < N:
    ans+=x*c
    count+=c
  else:
    ans+=x*(N-count)
    break
print(ans) from collections import defaultdict from bisect import bisect_left 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 for i in A:
  D[i]+=1 i A D[i]+=1 D[i] D i 1 for _ in range(M):
  a, b = map(int,input().split())
  D[b]+=a _ range(M) range M a, b = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b D[b]+=a D[b] D b a D_sorted = sorted(D.items(), key=lambda x:x[0], reverse = True) D_sorted sorted(D.items(), key=lambda x:x[0], reverse = True) sorted D.items() D.items D items key=lambda x:x[0] key lambda x:x[0] x[0] x 0 x reverse = True reverse True ans = 0 ans 0 count = 0 count 0 for x, c in D_sorted:
  if count+c < N:
    ans+=x*c
    count+=c
  else:
    ans+=x*(N-count)
    break x c D_sorted if count+c < N:
    ans+=x*c
    count+=c
  else:
    ans+=x*(N-count)
    break count+c < N count+c count c N ans+=x*c ans x*c x c count+=c count c ans+=x*(N-count) ans x*(N-count) x N-count N count break print(ans) print ans ans = 0 0 ans count = 0 0 count ans+=x*(N-count) x*(N-count) ans D_sorted = sorted(D.items(), key=lambda x:x[0], reverse = True) sorted(D.items(), key=lambda x:x[0], reverse = True) D_sorted A = list(map(int,input().split())) list(map(int,input().split())) A ans+=x*c x*c ans M = map(int,input().split()) map(int,input().split()) M a, b = map(int,input().split()) map(int,input().split()) a N, M = map(int,input().split()) map(int,input().split()) N count+=c c count D = defaultdict(int) defaultdict(int) D b = map(int,input().split()) map(int,input().split()) b
from collections import defaultdict
from bisect import bisect_left
N, M = map(int,input().split())
A = list(map(int,input().split()))
D = defaultdict(int)
for i in A:
  D[i]+=1
for _ in range(M):
  a, b = map(int,input().split())
  D[b]+=a
D_sorted = sorted(D.items(), key=lambda x:x[0], reverse = True)
ans = 0
count = 0
for x, c in D_sorted:
  if count+c < N:
    ans+=x*c
    count+=c
  else:
    ans+=x*(N-count)
    break
print(ans)