from collections import*
I=lambda:map(int,input().split())
n,m=I()
a=Counter(I())
for _ in[0]*m:b,c=I();a[c]+=b
s=0
for k,v in sorted(a.items())[::-1]:
 if n<v:exit(print(s+k*n))
 n-=v;s+=k*v from collections import* I=lambda:map(int,input().split()) I lambda:map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split n,m=I() n I() I m a=Counter(I()) a Counter(I()) Counter I() I for _ in[0]*m:b,c=I();a[c]+=b _ [0]*m [0] 0 m s=0 s 0 for k,v in sorted(a.items())[::-1]:
 if n<v:exit(print(s+k*n))
 n-=v;s+=k*v k v sorted(a.items())[::-1] (a.items()) sorted a.items() a.items a items ::-1 -1 if n<v:exit(print(s+k*n))
  n<v n v n-=v n v s+=k*v s k*v k v s+=k*v k*v s s=0 0 s m=I() I() m a=Counter(I()) Counter(I()) a n-=v v n I=lambda:map(int,input().split()) lambda:map(int,input().split()) I n,m=I() I() n
from collections import*
I=lambda:map(int,input().split())
n,m=I()
a=Counter(I())
for _ in[0]*m:b,c=I();a[c]+=b
s=0
for k,v in sorted(a.items())[::-1]:
 if n<v:exit(print(s+k*n))
 n-=v;s+=k*v