import sys

import heapq

input = sys.stdin.readline



n,m = list(map(int,input().split()))

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

heapq.heapify(A)



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

BC = sorted(BC,key = lambda x:-x[1])



for b,c in BC:

    for i in range(b):

        a = heapq.heappop(A)

        if a < c:

            heapq.heappush(A,c)

        else:

            heapq.heappush(A,a)

            break

print((sum(A)))
import sys

input = sys.stdin.readline



n,m = list(map(int,input().split()))

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

BC = [tuple(map(int,input().split())) for i in range(m)]

BC = sorted(BC,key=lambda x:-x[1])

cnt = 0

flag = True

while True:

    for b,c in BC:

        A += [c]*b

        cnt += b

        if cnt > n:

            break

    break

A = sorted(A,reverse=True)

print((sum(A[:n])))
import sys
import heapq

input = sys.stdin.readline
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
heapq.heapify(A)
BC = [list(map(int, input().split())) for i in range(m)]
BC = sorted(BC, key=lambda x: -x[1])
for b, c in BC:
    for i in range(b):
        a = heapq.heappop(A)
        if a < c:
            heapq.heappush(A, c)
        else:
            heapq.heappush(A, a)
            break
print((sum(A)))

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for i in range(m)]
BC = sorted(BC, key=lambda x: -x[1])
cnt = 0
flag = True
while True:
    for b, c in BC:
        A += [c] * b
        cnt += b
        if cnt > n:
            break
    break
A = sorted(A, reverse=True)
print((sum(A[:n])))

-import heapq -heapq.heapify(A) -BC = [list(map(int, input().split())) for i in range(m)] +BC = [tuple(map(int, input().split())) for i in range(m)] -for b, c in BC: -    for i in range(b): -        a = heapq.heappop(A) -        if a < c: -            heapq.heappush(A, c) -        else: -            heapq.heappush(A, a) +cnt = 0 +flag = True +while True: +    for b, c in BC: +        A += [c] * b +        cnt += b +        if cnt > n: -print((sum(A))) +    break +A = sorted(A, reverse=True) +print((sum(A[:n])))