import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: x[1], reverse = True)

for i in range(m):
    if a[0] >= bc[i][1]:
        break
    else:
        cnt = 0
        while cnt < bc[i][0]:
            heapq.heapreplace(a, bc[i][1])
            cnt += 1

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 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.sort(key = lambda x: x[1], reverse = True) bc.sort bc sort key = lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse = True reverse True for i in range(m):
    if a[0] >= bc[i][1]:
        break
    else:
        cnt = 0
        while cnt < bc[i][0]:
            heapq.heapreplace(a, bc[i][1])
            cnt += 1 i range(m) range m if a[0] >= bc[i][1]:
        break
    else:
        cnt = 0
        while cnt < bc[i][0]:
            heapq.heapreplace(a, bc[i][1])
            cnt += 1 a[0] >= bc[i][1] a[0] a 0 bc[i][1] [i] bc i 1 break cnt = 0 cnt 0 while cnt < bc[i][0]:
            heapq.heapreplace(a, bc[i][1])
            cnt += 1 cnt < bc[i][0] cnt bc[i][0] [i] bc i 0 heapq.heapreplace(a, bc[i][1]) heapq.heapreplace heapq heapreplace a bc[i][1] [i] bc i 1 cnt += 1 cnt 1 print(sum(a)) print sum(a) sum a n, m = map(int, input().split()) map(int, input().split()) n cnt = 0 0 cnt m = map(int, input().split()) map(int, input().split()) m bc = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] bc a = list(map(int, input().split())) list(map(int, input().split())) a cnt += 1 1 cnt
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key = lambda x: x[1], reverse = True)

for i in range(m):
    if a[0] >= bc[i][1]:
        break
    else:
        cnt = 0
        while cnt < bc[i][0]:
            heapq.heapreplace(a, bc[i][1])
            cnt += 1

print(sum(a))