n,m=map(int,input().split())
A = list(map(int,input().split()))
B=[]
for i in range(m):
    B.append(list(map(int,input().split())))
A.sort()
B.sort(key=lambda B: B[1], reverse=True)

i=j=0
ans = sum(A)
while j<n:
    newv = B[i][1]
    newc = min(B[i][0],n-j)
    if newv>A[j] :
        for k in range(newc):
            if newv<=A[j+k]:
                break
        else:
            k+=1
        ans+=newv*(k)-sum(A[j:j+k])
        i+=1
        j+=k
    else:
        break
    if i>=m :
        break

print(ans) 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 B=[] B [] for i in range(m):
    B.append(list(map(int,input().split()))) i range(m) range m B.append(list(map(int,input().split()))) B.append B append list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split A.sort() A.sort A sort B.sort(key=lambda B: B[1], reverse=True) B.sort B sort key=lambda B: B[1] key lambda B: B[1] B[1] B 1 B reverse=True reverse True i=j=0 i 0 =j=0 j 0 ans = sum(A) ans sum(A) sum A while j<n:
    newv = B[i][1]
    newc = min(B[i][0],n-j)
    if newv>A[j] :
        for k in range(newc):
            if newv<=A[j+k]:
                break
        else:
            k+=1
        ans+=newv*(k)-sum(A[j:j+k])
        i+=1
        j+=k
    else:
        break
    if i>=m :
        break j<n j n newv = B[i][1] newv B[i][1] [i] B i 1 newc = min(B[i][0],n-j) newc min(B[i][0],n-j) min B[i][0] [i] B i 0 n-j n j if newv>A[j] :
        for k in range(newc):
            if newv<=A[j+k]:
                break
        else:
            k+=1
        ans+=newv*(k)-sum(A[j:j+k])
        i+=1
        j+=k
    else:
        break
     newv>A[j] newv A[j] A j for k in range(newc):
            if newv<=A[j+k]:
                break
        else:
            k+=1
         k range(newc) range newc if newv<=A[j+k]:
                break
         newv<=A[j+k] newv A[j+k] A j+k j k break k+=1 k 1 ans+=newv*(k)-sum(A[j:j+k]) ans newv*(k)-sum(A[j:j+k]) newv*(k) newv k sum(A[j:j+k]) sum A[j:j+k] A j:j+k j j+k j k i+=1 i 1 j+=k j k break if i>=m :
        break i>=m i m break print(ans) print ans B=[] [] B n,m=map(int,input().split()) map(int,input().split()) n A = list(map(int,input().split())) list(map(int,input().split())) A j+=k k j j=0 0 j ans = sum(A) sum(A) ans m=map(int,input().split()) map(int,input().split()) m i+=1 1 i ans+=newv*(k)-sum(A[j:j+k]) newv*(k)-sum(A[j:j+k]) ans newv = B[i][1] B[i][1] newv newc = min(B[i][0],n-j) min(B[i][0],n-j) newc k+=1 1 k i=j=0 0 i
n,m=map(int,input().split())
A = list(map(int,input().split()))
B=[]
for i in range(m):
    B.append(list(map(int,input().split())))
A.sort()
B.sort(key=lambda B: B[1], reverse=True)

i=j=0
ans = sum(A)
while j<n:
    newv = B[i][1]
    newc = min(B[i][0],n-j)
    if newv>A[j] :
        for k in range(newc):
            if newv<=A[j+k]:
                break
        else:
            k+=1
        ans+=newv*(k)-sum(A[j:j+k])
        i+=1
        j+=k
    else:
        break
    if i>=m :
        break

print(ans)