n,m,*abc=map(int,open(0).read().split())
a=abc[:n]
a.sort()
bc=[[x,y] for x,y in zip(abc[n::2],abc[n+1::2])]
bc.sort(key=lambda x:x[1],reverse=True)
ai = 0
for b,c in bc:
    cc = b
    while ai<n and cc >0:
        if a[ai] < c:
            a[ai] = c
            cc -= 1
        ai +=1
    if ai ==n:
        break
print(sum(a))
         n,m,*abc=map(int,open(0).read().split()) n map(int,open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split m *abc abc a=abc[:n] a abc[:n] abc :n n a.sort() a.sort a sort [x,y] for x,y in zip(abc[n::2],abc[n+1::2]) for x,y in zip(abc[n::2],abc[n+1::2]) x y zip(abc[n::2],abc[n+1::2]) zip abc[n::2] abc n::2 n 2 abc[n+1::2] abc n+1::2 n+1 n 1 2 for x,y in zip(abc[n::2],abc[n+1::2]) [x,y] x y bc=[[x,y] for x,y in zip(abc[n::2],abc[n+1::2])] bc [[x,y] for x,y in zip(abc[n::2],abc[n+1::2])] 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 ai = 0 ai 0 for b,c in bc:
    cc = b
    while ai<n and cc >0:
        if a[ai] < c:
            a[ai] = c
            cc -= 1
        ai +=1
    if ai ==n:
        break b c bc cc = b cc b while ai<n and cc >0:
        if a[ai] < c:
            a[ai] = c
            cc -= 1
        ai +=1
     ai<n and cc >0 ai<n ai n cc >0 cc 0 if a[ai] < c:
            a[ai] = c
            cc -= 1
         a[ai] < c a[ai] a ai c a[ai] = c a[ai] a ai c cc -= 1 cc 1 ai +=1 ai 1 if ai ==n:
        break ai ==n ai n break print(sum(a)) print sum(a) sum a bc=[[x,y] for x,y in zip(abc[n::2],abc[n+1::2])] [[x,y] for x,y in zip(abc[n::2],abc[n+1::2])] bc m,*abc=map(int,open(0).read().split()) map(int,open(0).read().split()) m a=abc[:n] abc[:n] a ai +=1 1 ai ai = 0 0 ai n,m,*abc=map(int,open(0).read().split()) map(int,open(0).read().split()) n cc -= 1 1 cc cc = b b cc
n,m,*abc=map(int,open(0).read().split())
a=abc[:n]
a.sort()
bc=[[x,y] for x,y in zip(abc[n::2],abc[n+1::2])]
bc.sort(key=lambda x:x[1],reverse=True)
ai = 0
for b,c in bc:
    cc = b
    while ai<n and cc >0:
        if a[ai] < c:
            a[ai] = c
            cc -= 1
        ai +=1
    if ai ==n:
        break
print(sum(a))
        
