import sys
N,M=map(int,sys.stdin.readline().split())
L=sorted(list(map(lambda x: (1,int(x)), sys.stdin.readline().split()))
         +[tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
         ,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) import sys sys N,M=map(int,sys.stdin.readline().split()) N map(int,sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split M tuple(map(int, sys.stdin.readline().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) tuple(map(int, sys.stdin.readline().split())) tuple map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split L=sorted(list(map(lambda x: (1,int(x)), sys.stdin.readline().split()))
         +[tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
         ,key=lambda x: x[1],reverse=True) L sorted(list(map(lambda x: (1,int(x)), sys.stdin.readline().split()))
         +[tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
         ,key=lambda x: x[1],reverse=True) sorted list(map(lambda x: (1,int(x)), sys.stdin.readline().split()))
         +[tuple(map(int, sys.stdin.readline().split())) for _ in range(M)] list(map(lambda x: (1,int(x)), sys.stdin.readline().split())) list map(lambda x: (1,int(x)), sys.stdin.readline().split()) map lambda x: (1,int(x)) (1,int(x)) 1 int(x) int x x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)] 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 L=sorted(list(map(lambda x: (1,int(x)), sys.stdin.readline().split()))
         +[tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
         ,key=lambda x: x[1],reverse=True) sorted(list(map(lambda x: (1,int(x)), sys.stdin.readline().split()))
         +[tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
         ,key=lambda x: x[1],reverse=True) L N,M=map(int,sys.stdin.readline().split()) map(int,sys.stdin.readline().split()) N M=map(int,sys.stdin.readline().split()) map(int,sys.stdin.readline().split()) M k=0,0 0 k ans+=a*(N-k) a*(N-k) ans ans+=a*n a*n ans ans,k=0,0 0 ans k+=n n k
import sys
N,M=map(int,sys.stdin.readline().split())
L=sorted(list(map(lambda x: (1,int(x)), sys.stdin.readline().split()))
         +[tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
         ,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)