from heapq import heapify, heappush, heappop

import sys

input = sys.stdin.readline

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

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

A.sort()

B = [0] * M

C = [0] * M

for i in range(M):

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



cb = sorted(zip(C, B), reverse=True)



cnt = 0

exchange = []

for c, b in cb:

    exchange.extend([c] * b)

    cnt += b

    if cnt >= N:

        break



exchange.sort()



for _ in range(len(exchange)):

    m = heappop(A)

    heappush(A, max(m, exchange.pop()))



print((sum(A)))
import sys

input = sys.stdin.readline

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

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

B = [0] * M

C = [0] * M

for i in range(M):

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



cb = sorted(zip(C, B), reverse=True)



exchange = []

for c, b in cb:

    exchange.extend([c] * b)

    if len(exchange) >= N:

        break



A.extend(exchange)



A.sort(reverse=True)



print((sum(A[:N])))
from heapq import heapify, heappush, heappop
import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
B = [0] * M
C = [0] * M
for i in range(M):
    B[i], C[i] = list(map(int, input().split()))
cb = sorted(zip(C, B), reverse=True)
cnt = 0
exchange = []
for c, b in cb:
    exchange.extend([c] * b)
    cnt += b
    if cnt >= N:
        break
exchange.sort()
for _ in range(len(exchange)):
    m = heappop(A)
    heappush(A, max(m, exchange.pop()))
print((sum(A)))

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0] * M
C = [0] * M
for i in range(M):
    B[i], C[i] = list(map(int, input().split()))
cb = sorted(zip(C, B), reverse=True)
exchange = []
for c, b in cb:
    exchange.extend([c] * b)
    if len(exchange) >= N:
        break
A.extend(exchange)
A.sort(reverse=True)
print((sum(A[:N])))

-from heapq import heapify, heappush, heappop -A.sort() -cnt = 0 -    cnt += b -    if cnt >= N: +    if len(exchange) >= N: -exchange.sort() -for _ in range(len(exchange)): -    m = heappop(A) -    heappush(A, max(m, exchange.pop())) -print((sum(A))) +A.extend(exchange) +A.sort(reverse=True) +print((sum(A[:N])))