from collections import*
n,m,*d=map(int,open(0).read().split())
a=Counter(d[:n])
for b,c in zip(d[n::2],d[n+1::2]):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* n,m,*d=map(int,open(0).read().split()) n map(int,open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split m *d d a=Counter(d[:n]) a Counter(d[:n]) Counter d[:n] d :n n for b,c in zip(d[n::2],d[n+1::2]):a[c]+=b b c zip(d[n::2],d[n+1::2]) zip d[n::2] d n::2 n 2 d[n+1::2] d n+1::2 n+1 n 1 2 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 n,m,*d=map(int,open(0).read().split()) map(int,open(0).read().split()) n m,*d=map(int,open(0).read().split()) map(int,open(0).read().split()) m s=0 0 s n-=v v n a=Counter(d[:n]) Counter(d[:n]) a s+=k*v k*v s
from collections import*
n,m,*d=map(int,open(0).read().split())
a=Counter(d[:n])
for b,c in zip(d[n::2],d[n+1::2]):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