n,m=map(int,input().split())
l=list(map(int,input().split()))
d=dict()
for i in range(m):
  a,b=map(int,input().split())
  if b in d:
    d[b]+=a
  else:
    d[b]=a
x=sorted(d.keys())[::-1]
now=0
for y in x:
  now+=d[y]
  l+=[y]*min(n,d[y])
  if now>n:
    break
print(sum(sorted(l)[::-1][:n])) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l=list(map(int,input().split())) l list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split d=dict() d dict() dict for i in range(m):
  a,b=map(int,input().split())
  if b in d:
    d[b]+=a
  else:
    d[b]=a i range(m) range m a,b=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b if b in d:
    d[b]+=a
  else:
    d[b]=a b in d b d d[b]+=a d[b] d b a d[b]=a d[b] d b a x=sorted(d.keys())[::-1] x sorted(d.keys())[::-1] (d.keys()) sorted d.keys() d.keys d keys ::-1 -1 now=0 now 0 for y in x:
  now+=d[y]
  l+=[y]*min(n,d[y])
  if now>n:
    break y x now+=d[y] now d[y] d y l+=[y]*min(n,d[y]) l [y]*min(n,d[y]) [y] y min(n,d[y]) min n d[y] d y if now>n:
    break now>n now n break print(sum(sorted(l)[::-1][:n])) print sum(sorted(l)[::-1][:n]) sum sorted(l)[::-1][:n] [::-1] (l) sorted l ::-1 -1 :n n d=dict() dict() d m=map(int,input().split()) map(int,input().split()) m a,b=map(int,input().split()) map(int,input().split()) a x=sorted(d.keys())[::-1] sorted(d.keys())[::-1] x now=0 0 now b=map(int,input().split()) map(int,input().split()) b now+=d[y] d[y] now l+=[y]*min(n,d[y]) [y]*min(n,d[y]) l l=list(map(int,input().split())) list(map(int,input().split())) l n,m=map(int,input().split()) map(int,input().split()) n
n,m=map(int,input().split())
l=list(map(int,input().split()))
d=dict()
for i in range(m):
  a,b=map(int,input().split())
  if b in d:
    d[b]+=a
  else:
    d[b]=a
x=sorted(d.keys())[::-1]
now=0
for y in x:
  now+=d[y]
  l+=[y]*min(n,d[y])
  if now>n:
    break
print(sum(sorted(l)[::-1][:n]))