import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  # C降順にソート
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST)) import heapq heapq N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A_LIST = list(map(int, input().split())) A_LIST list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split BC_LIST = [] BC_LIST [] heapq.heapify(A_LIST) heapq.heapify heapq heapify A_LIST for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c]) i range(M) range M b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c BC_LIST.append([b, c]) BC_LIST.append BC_LIST append [b, c] b c BC_LIST.sort(reverse=True, key=lambda x: x[1]) BC_LIST.sort BC_LIST sort reverse=True reverse True key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break b c BC_LIST for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break _ range(b) range b tmp = heapq.heappop(A_LIST) tmp heapq.heappop(A_LIST) heapq.heappop heapq heappop A_LIST if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break tmp < c tmp c heapq.heappush(A_LIST, c) heapq.heappush heapq heappush A_LIST c heapq.heappush(A_LIST, tmp) heapq.heappush heapq heappush A_LIST tmp break print(sum(A_LIST)) print sum(A_LIST) sum A_LIST tmp = heapq.heappop(A_LIST) heapq.heappop(A_LIST) tmp c = map(int, input().split()) map(int, input().split()) c b, c = map(int, input().split()) map(int, input().split()) b N, M = map(int, input().split()) map(int, input().split()) N A_LIST = list(map(int, input().split())) list(map(int, input().split())) A_LIST M = map(int, input().split()) map(int, input().split()) M BC_LIST = [] [] BC_LIST
import heapq

N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
heapq.heapify(A_LIST)
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
BC_LIST.sort(reverse=True, key=lambda x: x[1])  # C降順にソート
for b, c in BC_LIST:
    for _ in range(b):
        tmp = heapq.heappop(A_LIST)
        if tmp < c:
            heapq.heappush(A_LIST, c)
        else:
            heapq.heappush(A_LIST, tmp)
            break
print(sum(A_LIST))
