import heapq

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

a = list(map(int,input().split()))
bc = []
for _ in range(m):
    b, c = (int(x) for x in input().split())
    bc.append([b, c])
bc = sorted(bc, key=lambda x: -x[1])

heapq.heapify(a)

for i in range(m):
    count = 0
    if bc[i][1] < a[0]:
        break
    while a[0] < bc[i][1] and count < bc[i][0]:
        heapq.heappop(a)
        heapq.heappush(a,bc[i][1])
        count += 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 bc = [] bc [] for _ in range(m):
    b, c = (int(x) for x in input().split())
    bc.append([b, c]) _ range(m) range m int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x b, c = (int(x) for x in input().split()) b (int(x) for x in input().split()) c bc.append([b, c]) bc.append bc append [b, c] b c bc = sorted(bc, key=lambda x: -x[1]) bc sorted(bc, key=lambda x: -x[1]) sorted bc key=lambda x: -x[1] key lambda x: -x[1] -x[1] x[1] x 1 x heapq.heapify(a) heapq.heapify heapq heapify a for i in range(m):
    count = 0
    if bc[i][1] < a[0]:
        break
    while a[0] < bc[i][1] and count < bc[i][0]:
        heapq.heappop(a)
        heapq.heappush(a,bc[i][1])
        count += 1 i range(m) range m count = 0 count 0 if bc[i][1] < a[0]:
        break
     bc[i][1] < a[0] bc[i][1] [i] bc i 1 a[0] a 0 break while a[0] < bc[i][1] and count < bc[i][0]:
        heapq.heappop(a)
        heapq.heappush(a,bc[i][1])
        count += 1 a[0] < bc[i][1] and count < bc[i][0] a[0] < bc[i][1] a[0] a 0 bc[i][1] [i] bc i 1 count < bc[i][0] count bc[i][0] [i] bc i 0 heapq.heappop(a) heapq.heappop heapq heappop a heapq.heappush(a,bc[i][1]) heapq.heappush heapq heappush a bc[i][1] [i] bc i 1 count += 1 count 1 print(sum(a)) print sum(a) sum a a = list(map(int,input().split())) list(map(int,input().split())) a bc = sorted(bc, key=lambda x: -x[1]) sorted(bc, key=lambda x: -x[1]) bc count += 1 1 count b, c = (int(x) for x in input().split()) (int(x) for x in input().split()) b count = 0 0 count c = (int(x) for x in input().split()) (int(x) for x in input().split()) c m = map(int,input().split()) map(int,input().split()) m n,m = map(int,input().split()) map(int,input().split()) n bc = [] [] bc
import heapq

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

a = list(map(int,input().split()))
bc = []
for _ in range(m):
    b, c = (int(x) for x in input().split())
    bc.append([b, c])
bc = sorted(bc, key=lambda x: -x[1])

heapq.heapify(a)

for i in range(m):
    count = 0
    if bc[i][1] < a[0]:
        break
    while a[0] < bc[i][1] and count < bc[i][0]:
        heapq.heappop(a)
        heapq.heappush(a,bc[i][1])
        count += 1
print(sum(a))