n,m=map(int,input().split())
a=list(map(int,input().split()))
d=[]
ans=0
for i in range(n):
  d.append([a[i],1])
for i in range(m):
  b,c=map(int,input().split())
  d.append([c,b])
d.sort(reverse=True)
for i in range(n+m):
  if n==0:
    break
  ans+=d[i][0]*min(n,d[i][1])
  n-=min(n,d[i][1])
print(ans) 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=[] d [] ans=0 ans 0 for i in range(n):
  d.append([a[i],1]) i range(n) range n d.append([a[i],1]) d.append d append [a[i],1] a[i] a i 1 for i in range(m):
  b,c=map(int,input().split())
  d.append([c,b]) i range(m) range m b,c=map(int,input().split()) b map(int,input().split()) map int input().split() ().split () input split c d.append([c,b]) d.append d append [c,b] c b d.sort(reverse=True) d.sort d sort reverse=True reverse True for i in range(n+m):
  if n==0:
    break
  ans+=d[i][0]*min(n,d[i][1])
  n-=min(n,d[i][1]) i range(n+m) range n+m n m if n==0:
    break
   n==0 n 0 break ans+=d[i][0]*min(n,d[i][1]) ans d[i][0]*min(n,d[i][1]) d[i][0] [i] d i 0 min(n,d[i][1]) min n d[i][1] [i] d i 1 n-=min(n,d[i][1]) n min(n,d[i][1]) min n d[i][1] [i] d i 1 print(ans) print ans ans+=d[i][0]*min(n,d[i][1]) d[i][0]*min(n,d[i][1]) ans a=list(map(int,input().split())) list(map(int,input().split())) a d=[] [] d ans=0 0 ans n,m=map(int,input().split()) map(int,input().split()) n b,c=map(int,input().split()) map(int,input().split()) b c=map(int,input().split()) map(int,input().split()) c m=map(int,input().split()) map(int,input().split()) m n-=min(n,d[i][1]) min(n,d[i][1]) n
n,m=map(int,input().split())
a=list(map(int,input().split()))
d=[]
ans=0
for i in range(n):
  d.append([a[i],1])
for i in range(m):
  b,c=map(int,input().split())
  d.append([c,b])
d.sort(reverse=True)
for i in range(n+m):
  if n==0:
    break
  ans+=d[i][0]*min(n,d[i][1])
  n-=min(n,d[i][1])
print(ans)