n,m = map(int,input().split())
A = list(map(int,input().split()))
tehuda = []
for i in range(m):
    b,c = map(int,input().split())
    tehuda.append((b,c))
# とりあえず和
sumA = sum(A)
import heapq
heapq.heapify(A)
tehuda = sorted(tehuda,key = lambda x:x[1])
#print(tehuda)
over = True
while tehuda:
    if not over:
        break
    b,c = tehuda.pop()
    while True:
        m = heapq.heappop(A)
        #print(m,c)
        if m >= c:
            over = False
            break
        else:
            b -= 1
            sumA -= m
            sumA += c
            heapq.heappush(A,c)
            if b == 0:
                break
print(sumA) 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 tehuda = [] tehuda [] for i in range(m):
    b,c = map(int,input().split())
    tehuda.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 tehuda.append((b,c)) tehuda.append tehuda append (b,c) b c sumA = sum(A) sumA sum(A) sum A import heapq heapq heapq.heapify(A) heapq.heapify heapq heapify A tehuda = sorted(tehuda,key = lambda x:x[1]) tehuda sorted(tehuda,key = lambda x:x[1]) sorted tehuda key = lambda x:x[1] key lambda x:x[1] x[1] x 1 x over = True over True while tehuda:
    if not over:
        break
    b,c = tehuda.pop()
    while True:
        m = heapq.heappop(A)
        #print(m,c)
        if m >= c:
            over = False
            break
        else:
            b -= 1
            sumA -= m
            sumA += c
            heapq.heappush(A,c)
            if b == 0:
                break tehuda if not over:
        break
     not over over break b,c = tehuda.pop() b tehuda.pop() tehuda.pop tehuda pop c while True:
        m = heapq.heappop(A)
        #print(m,c)
        if m >= c:
            over = False
            break
        else:
            b -= 1
            sumA -= m
            sumA += c
            heapq.heappush(A,c)
            if b == 0:
                break True m = heapq.heappop(A) m heapq.heappop(A) heapq.heappop heapq heappop A if m >= c:
            over = False
            break
        else:
            b -= 1
            sumA -= m
            sumA += c
            heapq.heappush(A,c)
            if b == 0:
                break m >= c m c over = False over False break b -= 1 b 1 sumA -= m sumA m sumA += c sumA c heapq.heappush(A,c) heapq.heappush heapq heappush A c if b == 0:
                break b == 0 b 0 break print(sumA) print sumA tehuda = [] [] tehuda c = map(int,input().split()) map(int,input().split()) c b,c = tehuda.pop() tehuda.pop() b over = False False over b -= 1 1 b m = map(int,input().split()) map(int,input().split()) m n,m = map(int,input().split()) map(int,input().split()) n tehuda = sorted(tehuda,key = lambda x:x[1]) sorted(tehuda,key = lambda x:x[1]) tehuda over = True True over A = list(map(int,input().split())) list(map(int,input().split())) A c = tehuda.pop() tehuda.pop() c sumA -= m m sumA b,c = map(int,input().split()) map(int,input().split()) b sumA += c c sumA m = heapq.heappop(A) heapq.heappop(A) m sumA = sum(A) sum(A) sumA
n,m = map(int,input().split())
A = list(map(int,input().split()))
tehuda = []
for i in range(m):
    b,c = map(int,input().split())
    tehuda.append((b,c))
# とりあえず和
sumA = sum(A)
import heapq
heapq.heapify(A)
tehuda = sorted(tehuda,key = lambda x:x[1])
#print(tehuda)
over = True
while tehuda:
    if not over:
        break
    b,c = tehuda.pop()
    while True:
        m = heapq.heappop(A)
        #print(m,c)
        if m >= c:
            over = False
            break
        else:
            b -= 1
            sumA -= m
            sumA += c
            heapq.heappush(A,c)
            if b == 0:
                break
print(sumA)
