import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
B = []
C = []
CB = []
for _ in range(M):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)
    CB.append((c, b))
CB.sort(reverse=True)
for c, b in CB:
    for j in range(b):
        tmp = heapq.heappop(A)
        if tmp >= c:
            heapq.heappush(A, tmp)
            break
        else:
            heapq.heappush(A, c)
print(sum(A)) 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 heapq.heapify(A) heapq.heapify heapq heapify A B = [] B [] C = [] C [] CB = [] CB [] for _ in range(M):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)
    CB.append((c, b)) _ range(M) range M b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c B.append(b) B.append B append b C.append(c) C.append C append c CB.append((c, b)) CB.append CB append (c, b) c b CB.sort(reverse=True) CB.sort CB sort reverse=True reverse True for c, b in CB:
    for j in range(b):
        tmp = heapq.heappop(A)
        if tmp >= c:
            heapq.heappush(A, tmp)
            break
        else:
            heapq.heappush(A, c) c b CB for j in range(b):
        tmp = heapq.heappop(A)
        if tmp >= c:
            heapq.heappush(A, tmp)
            break
        else:
            heapq.heappush(A, c) j range(b) range b tmp = heapq.heappop(A) tmp heapq.heappop(A) heapq.heappop heapq heappop A if tmp >= c:
            heapq.heappush(A, tmp)
            break
        else:
            heapq.heappush(A, c) tmp >= c tmp c heapq.heappush(A, tmp) heapq.heappush heapq heappush A tmp break heapq.heappush(A, c) heapq.heappush heapq heappush A c print(sum(A)) print sum(A) sum A M = map(int, input().split()) map(int, input().split()) M b, c = map(int, input().split()) map(int, input().split()) b CB = [] [] CB B = [] [] B c = map(int, input().split()) map(int, input().split()) c N, M = map(int, input().split()) map(int, input().split()) N A = list(map(int, input().split())) list(map(int, input().split())) A C = [] [] C tmp = heapq.heappop(A) heapq.heappop(A) tmp
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
B = []
C = []
CB = []
for _ in range(M):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)
    CB.append((c, b))
CB.sort(reverse=True)
for c, b in CB:
    for j in range(b):
        tmp = heapq.heappop(A)
        if tmp >= c:
            heapq.heappush(A, tmp)
            break
        else:
            heapq.heappush(A, c)
print(sum(A))
