N,M=list(map(int,input().split()))

L=sorted(list([(1,int(x)) for x in input().split()])

         +[tuple(map(int,input().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

N,M=list(map(int,sys.stdin.readline().split()))

L=sorted(list([(1,int(x)) for x in 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)
N, M = list(map(int, input().split()))
L = sorted(
    list([(1, int(x)) for x in input().split()])
    + [tuple(map(int, input().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

N, M = list(map(int, sys.stdin.readline().split()))
L = sorted(
    list([(1, int(x)) for x in 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)

-N, M = list(map(int, input().split())) +import sys + +N, M = list(map(int, sys.stdin.readline().split())) -    list([(1, int(x)) for x in input().split()]) -    + [tuple(map(int, input().split())) for _ in range(M)], +    list([(1, int(x)) for x in sys.stdin.readline().split()]) +    + [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)],