import sys
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
origin = sum(A)
heapq.heapify(A)

BC = [list(map(int, input().split())) for _ in range(M)]
BC = sorted(BC, reverse=True, key=lambda x: x[1])

count = 0

for i in range(M):
    b = BC[i][0]
    c = BC[i][1]
    for _ in range(b):
        smallest = heapq.heappop(A)
        tmp = c - smallest
        if tmp <= 0:
            heapq.heappush(A, smallest)
            break
        else:
            heapq.heappush(A, c)
            origin += tmp
            count += 1
            if count >= N:
                print(origin)
                sys.exit()

print(origin) import sys sys import heapq heapq N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split origin = sum(A) origin sum(A) sum A heapq.heapify(A) heapq.heapify heapq heapify A list(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split BC = [list(map(int, input().split())) for _ in range(M)] BC [list(map(int, input().split())) for _ in range(M)] BC = sorted(BC, reverse=True, key=lambda x: x[1]) BC sorted(BC, reverse=True, key=lambda x: x[1]) sorted BC reverse=True reverse True key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x count = 0 count 0 for i in range(M):
    b = BC[i][0]
    c = BC[i][1]
    for _ in range(b):
        smallest = heapq.heappop(A)
        tmp = c - smallest
        if tmp <= 0:
            heapq.heappush(A, smallest)
            break
        else:
            heapq.heappush(A, c)
            origin += tmp
            count += 1
            if count >= N:
                print(origin)
                sys.exit() i range(M) range M b = BC[i][0] b BC[i][0] [i] BC i 0 c = BC[i][1] c BC[i][1] [i] BC i 1 for _ in range(b):
        smallest = heapq.heappop(A)
        tmp = c - smallest
        if tmp <= 0:
            heapq.heappush(A, smallest)
            break
        else:
            heapq.heappush(A, c)
            origin += tmp
            count += 1
            if count >= N:
                print(origin)
                sys.exit() _ range(b) range b smallest = heapq.heappop(A) smallest heapq.heappop(A) heapq.heappop heapq heappop A tmp = c - smallest tmp c - smallest c smallest if tmp <= 0:
            heapq.heappush(A, smallest)
            break
        else:
            heapq.heappush(A, c)
            origin += tmp
            count += 1
            if count >= N:
                print(origin)
                sys.exit() tmp <= 0 tmp 0 heapq.heappush(A, smallest) heapq.heappush heapq heappush A smallest break heapq.heappush(A, c) heapq.heappush heapq heappush A c origin += tmp origin tmp count += 1 count 1 if count >= N:
                print(origin)
                sys.exit() count >= N count N print(origin) print origin sys.exit() sys.exit sys exit print(origin) print origin origin = sum(A) sum(A) origin smallest = heapq.heappop(A) heapq.heappop(A) smallest count += 1 1 count N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M origin += tmp tmp origin b = BC[i][0] BC[i][0] b count = 0 0 count BC = sorted(BC, reverse=True, key=lambda x: x[1]) sorted(BC, reverse=True, key=lambda x: x[1]) BC c = BC[i][1] BC[i][1] c A = list(map(int, input().split())) list(map(int, input().split())) A tmp = c - smallest c - smallest tmp BC = [list(map(int, input().split())) for _ in range(M)] [list(map(int, input().split())) for _ in range(M)] BC
import sys
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
origin = sum(A)
heapq.heapify(A)

BC = [list(map(int, input().split())) for _ in range(M)]
BC = sorted(BC, reverse=True, key=lambda x: x[1])

count = 0

for i in range(M):
    b = BC[i][0]
    c = BC[i][1]
    for _ in range(b):
        smallest = heapq.heappop(A)
        tmp = c - smallest
        if tmp <= 0:
            heapq.heappush(A, smallest)
            break
        else:
            heapq.heappush(A, c)
            origin += tmp
            count += 1
            if count >= N:
                print(origin)
                sys.exit()

print(origin)
