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