import heapq
push, pop = heapq.heappush, heapq.heappop

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

def modify():
    heapq.heapify(a)
    
    bc = [list(map(int, input().split())) for _ in range(m)]
    bc.sort(key=lambda x:x[1], reverse=True)
    
    for b,c in bc:
        for _ in range(b):
            p = pop(a)
            if p < c:
                push(a, c)
            else:
                # キューに戻す
                push(a, p)
                return

modify()            
print(sum(a)) import heapq heapq push, pop = heapq.heappush, heapq.heappop push heapq.heappush heapq heappush pop heapq.heappop heapq heappop n,m = list(map(int, input().split())) n list(map(int, input().split())) list 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 def modify():
    heapq.heapify(a)
    
    bc = [list(map(int, input().split())) for _ in range(m)]
    bc.sort(key=lambda x:x[1], reverse=True)
    
    for b,c in bc:
        for _ in range(b):
            p = pop(a)
            if p < c:
                push(a, c)
            else:
                # キューに戻す
                push(a, p)
                return modify 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 b,c in bc:
        for _ in range(b):
            p = pop(a)
            if p < c:
                push(a, c)
            else:
                # キューに戻す
                push(a, p)
                return b c bc for _ in range(b):
            p = pop(a)
            if p < c:
                push(a, c)
            else:
                # キューに戻す
                push(a, p)
                return _ range(b) range b p = pop(a) p pop(a) pop a if p < c:
                push(a, c)
            else:
                # キューに戻す
                push(a, p)
                return p < c p c push(a, c) push a c push(a, p) push a p return modify() modify print(sum(a)) print sum(a) sum a pop = heapq.heappush, heapq.heappop heapq.heappop pop n,m = list(map(int, input().split())) list(map(int, input().split())) n a = list(map(int, input().split())) list(map(int, input().split())) a push, pop = heapq.heappush, heapq.heappop heapq.heappush push m = list(map(int, input().split())) list(map(int, input().split())) m def modify():
    heapq.heapify(a)
    
    bc = [list(map(int, input().split())) for _ in range(m)]
    bc.sort(key=lambda x:x[1], reverse=True)
    
    for b,c in bc:
        for _ in range(b):
            p = pop(a)
            if p < c:
                push(a, c)
            else:
                # キューに戻す
                push(a, p)
                return def modify():
    heapq.heapify(a)
    
    bc = [list(map(int, input().split())) for _ in range(m)]
    bc.sort(key=lambda x:x[1], reverse=True)
    
    for b,c in bc:
        for _ in range(b):
            p = pop(a)
            if p < c:
                push(a, c)
            else:
                # キューに戻す
                push(a, p)
                return modify
import heapq
push, pop = heapq.heappush, heapq.heappop

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

def modify():
    heapq.heapify(a)
    
    bc = [list(map(int, input().split())) for _ in range(m)]
    bc.sort(key=lambda x:x[1], reverse=True)
    
    for b,c in bc:
        for _ in range(b):
            p = pop(a)
            if p < c:
                push(a, c)
            else:
                # キューに戻す
                push(a, p)
                return

modify()            
print(sum(a))