from collections import defaultdict

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

A=list(map(int, input().split()))

d=defaultdict(int)

for a in A:

  d[a]+=1

for i in range(M):

  B, C=list(map(int, input().split()))

  d[C]+=B

index_list=sorted(d)

ans=0

ans_size=0

for i in range(len(index_list)-1, -1, -1):

  card=index_list[i]

  if d[card]+ans_size>=N:

    ans+=(N-ans_size)*card

    break

  else:

    ans+=d[card]*card

    ans_size+=d[card]

print(ans)
import heapq



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

A=list(map(int, input().split()))

heapq.heapify(A)

BC=[list(map(int, input().split())) for _ in range(M)]

BC.sort(key=lambda x:(x[1], x[0]), reverse=True)



for b, c in BC:

    if len(A) and A[0]>=c:

        break

    for i in range(b):

        if len(A) and A[0]>=c:

            break

        heapq.heappop(A)

        heapq.heappush(A, c)



print((sum(A)))
from collections import defaultdict

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
d = defaultdict(int)
for a in A:
    d[a] += 1
for i in range(M):
    B, C = list(map(int, input().split()))
    d[C] += B
index_list = sorted(d)
ans = 0
ans_size = 0
for i in range(len(index_list) - 1, -1, -1):
    card = index_list[i]
    if d[card] + ans_size >= N:
        ans += (N - ans_size) * card
        break
    else:
        ans += d[card] * card
        ans_size += d[card]
print(ans)

import heapq

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
heapq.heapify(A)
BC = [list(map(int, input().split())) for _ in range(M)]
BC.sort(key=lambda x: (x[1], x[0]), reverse=True)
for b, c in BC:
    if len(A) and A[0] >= c:
        break
    for i in range(b):
        if len(A) and A[0] >= c:
            break
        heapq.heappop(A)
        heapq.heappush(A, c)
print((sum(A)))

-from collections import defaultdict +import heapq -d = defaultdict(int) -for a in A: -    d[a] += 1 -for i in range(M): -    B, C = list(map(int, input().split())) -    d[C] += B -index_list = sorted(d) -ans = 0 -ans_size = 0 -for i in range(len(index_list) - 1, -1, -1): -    card = index_list[i] -    if d[card] + ans_size >= N: -        ans += (N - ans_size) * card +heapq.heapify(A) +BC = [list(map(int, input().split())) for _ in range(M)] +BC.sort(key=lambda x: (x[1], x[0]), reverse=True) +for b, c in BC: +    if len(A) and A[0] >= c: -    else: -        ans += d[card] * card -        ans_size += d[card] -print(ans) +    for i in range(b): +        if len(A) and A[0] >= c: +            break +        heapq.heappop(A) +        heapq.heappush(A, c) +print((sum(A)))