N,M=map(int,input().split())
L=list(map(lambda x: (1,int(x)), input().split()))
for _ in range(M):
  L.append(tuple(map(int,input().split())))
L=sorted(L,key=lambda x: x[1],reverse=True)
ans,k=0,0
for n,a in L:
  if n+k>=N:
    ans+=a*(N-k)
    break
  else:
    ans+=a*n
    k+=n
print(ans) N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L=list(map(lambda x: (1,int(x)), input().split())) L list(map(lambda x: (1,int(x)), input().split())) list map(lambda x: (1,int(x)), input().split()) map lambda x: (1,int(x)) (1,int(x)) 1 int(x) int x x input().split() ().split () input split for _ in range(M):
  L.append(tuple(map(int,input().split()))) _ range(M) range M L.append(tuple(map(int,input().split()))) L.append L append tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split L=sorted(L,key=lambda x: x[1],reverse=True) L sorted(L,key=lambda x: x[1],reverse=True) sorted L key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True ans,k=0,0 ans 0 k 0 for n,a in L:
  if n+k>=N:
    ans+=a*(N-k)
    break
  else:
    ans+=a*n
    k+=n n a L if n+k>=N:
    ans+=a*(N-k)
    break
  else:
    ans+=a*n
    k+=n n+k>=N n+k n k N ans+=a*(N-k) ans a*(N-k) a N-k N k break ans+=a*n ans a*n a n k+=n k n print(ans) print ans k=0,0 0 k k+=n n k ans+=a*(N-k) a*(N-k) ans L=sorted(L,key=lambda x: x[1],reverse=True) sorted(L,key=lambda x: x[1],reverse=True) L M=map(int,input().split()) map(int,input().split()) M L=list(map(lambda x: (1,int(x)), input().split())) list(map(lambda x: (1,int(x)), input().split())) L ans,k=0,0 0 ans N,M=map(int,input().split()) map(int,input().split()) N ans+=a*n a*n ans
N,M=map(int,input().split())
L=list(map(lambda x: (1,int(x)), input().split()))
for _ in range(M):
  L.append(tuple(map(int,input().split())))
L=sorted(L,key=lambda x: x[1],reverse=True)
ans,k=0,0
for n,a in L:
  if n+k>=N:
    ans+=a*(N-k)
    break
  else:
    ans+=a*n
    k+=n
print(ans)