n,m = map(int,input().split())
li = list(map(int,input().split()))
bc = [list(map(int,input().split())) for _ in range(m)]

bc.sort(key=lambda x:x[1],reverse=True)
l = []
ans = 0

for b,c in bc:
    l += [c]*b
    if len(l) > n:
        break
    
li += l
li.sort(reverse=True)
print(sum(li[:n])) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m li = list(map(int,input().split())) li 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)] 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 l = [] l [] ans = 0 ans 0 for b,c in bc:
    l += [c]*b
    if len(l) > n:
        break
     b c bc l += [c]*b l [c]*b [c] c b if len(l) > n:
        break
     len(l) > n len(l) len l n break li += l li l li.sort(reverse=True) li.sort li sort reverse=True reverse True print(sum(li[:n])) print sum(li[:n]) sum li[:n] li :n n l = [] [] l l += [c]*b [c]*b l li = list(map(int,input().split())) list(map(int,input().split())) li li += l l li n,m = map(int,input().split()) map(int,input().split()) n bc = [list(map(int,input().split())) for _ in range(m)] [list(map(int,input().split())) for _ in range(m)] bc ans = 0 0 ans m = map(int,input().split()) map(int,input().split()) m
n,m = map(int,input().split())
li = list(map(int,input().split()))
bc = [list(map(int,input().split())) for _ in range(m)]

bc.sort(key=lambda x:x[1],reverse=True)
l = []
ans = 0

for b,c in bc:
    l += [c]*b
    if len(l) > n:
        break
    
li += l
li.sort(reverse=True)
print(sum(li[:n]))
