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

sorted_ab=sorted(bc, reverse=True, key=lambda x: x[1])
new_ab=[]
ans=[]

for i in range(m):
    if len(new_ab)<=n:
        tmp_l=[sorted_ab[i][1]]*sorted_ab[i][0]
        new_ab+=tmp_l
    else:
        break

final_list=a+new_ab
final_list.sort(reverse=True)
print(sum(final_list[:n])) 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)] sorted_ab=sorted(bc, reverse=True, key=lambda x: x[1]) sorted_ab sorted(bc, reverse=True, key=lambda x: x[1]) sorted bc reverse=True reverse True key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x new_ab=[] new_ab [] ans=[] ans [] for i in range(m):
    if len(new_ab)<=n:
        tmp_l=[sorted_ab[i][1]]*sorted_ab[i][0]
        new_ab+=tmp_l
    else:
        break i range(m) range m if len(new_ab)<=n:
        tmp_l=[sorted_ab[i][1]]*sorted_ab[i][0]
        new_ab+=tmp_l
    else:
        break len(new_ab)<=n len(new_ab) len new_ab n tmp_l=[sorted_ab[i][1]]*sorted_ab[i][0] tmp_l [sorted_ab[i][1]]*sorted_ab[i][0] [sorted_ab[i][1]] sorted_ab[i][1] [i] sorted_ab i 1 sorted_ab[i][0] [i] sorted_ab i 0 new_ab+=tmp_l new_ab tmp_l break final_list=a+new_ab final_list a+new_ab a new_ab final_list.sort(reverse=True) final_list.sort final_list sort reverse=True reverse True print(sum(final_list[:n])) print sum(final_list[:n]) sum final_list[:n] final_list :n n n,m=map(int,input().split()) map(int,input().split()) n ans=[] [] ans tmp_l=[sorted_ab[i][1]]*sorted_ab[i][0] [sorted_ab[i][1]]*sorted_ab[i][0] tmp_l sorted_ab=sorted(bc, reverse=True, key=lambda x: x[1]) sorted(bc, reverse=True, key=lambda x: x[1]) sorted_ab a=list(map(int,input().split())) list(map(int,input().split())) a final_list=a+new_ab a+new_ab final_list bc=[list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] bc new_ab=[] [] new_ab new_ab+=tmp_l tmp_l new_ab m=map(int,input().split()) map(int,input().split()) m
n,m=map(int,input().split())
a=list(map(int,input().split()))
bc=[list(map(int, input().split())) for _ in range(m)]

sorted_ab=sorted(bc, reverse=True, key=lambda x: x[1])
new_ab=[]
ans=[]

for i in range(m):
    if len(new_ab)<=n:
        tmp_l=[sorted_ab[i][1]]*sorted_ab[i][0]
        new_ab+=tmp_l
    else:
        break

final_list=a+new_ab
final_list.sort(reverse=True)
print(sum(final_list[:n]))