from heapq import *
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split()))for _ in range(m)]

heapify(a)
bc = sorted(bc,key=lambda x:x[1],reverse=True)

for b,c in bc:
    for i in range(b):
        tmp = heappop(a)
        if tmp >= c:
            heappush(a,tmp)
            break
        else:
            heappush(a,c)

print(sum(a)) from heapq import * 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 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)] heapify(a) heapify a bc = sorted(bc,key=lambda x:x[1],reverse=True) bc sorted(bc,key=lambda x:x[1],reverse=True) sorted bc 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 i in range(b):
        tmp = heappop(a)
        if tmp >= c:
            heappush(a,tmp)
            break
        else:
            heappush(a,c) b c bc for i in range(b):
        tmp = heappop(a)
        if tmp >= c:
            heappush(a,tmp)
            break
        else:
            heappush(a,c) i range(b) range b tmp = heappop(a) tmp heappop(a) heappop a if tmp >= c:
            heappush(a,tmp)
            break
        else:
            heappush(a,c) tmp >= c tmp c heappush(a,tmp) heappush a tmp break heappush(a,c) heappush a c print(sum(a)) print sum(a) sum a n,m = map(int,input().split()) map(int,input().split()) n m = map(int,input().split()) map(int,input().split()) m a = list(map(int,input().split())) list(map(int,input().split())) a bc = sorted(bc,key=lambda x:x[1],reverse=True) sorted(bc,key=lambda x:x[1],reverse=True) bc bc = [list(map(int,input().split()))for _ in range(m)] [list(map(int,input().split()))for _ in range(m)] bc tmp = heappop(a) heappop(a) tmp
from heapq import *
n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split()))for _ in range(m)]

heapify(a)
bc = sorted(bc,key=lambda x:x[1],reverse=True)

for b,c in bc:
    for i in range(b):
        tmp = heappop(a)
        if tmp >= c:
            heappush(a,tmp)
            break
        else:
            heappush(a,c)

print(sum(a))