n,m=map(int,input().split())
a=list(map(int,input().split()))
arr=[]

for i in range(m):
    b,c=map(int,input().split())
    arr.append((b,c))

a=sorted(a)
arr=sorted(arr,key=lambda x:-x[1])

flag=0
left=0
for tup in arr:
    for i in range(left,min(left+tup[0],n)):
        if tup[1]>a[i]:
            a[i]=tup[1]
        else:
            flag=-1
            break
        if i==n-1:
            flag=-1
            break
    left+=tup[0]
    if flag==-1:
        break

print(sum(a)) 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 arr=[] arr [] for i in range(m):
    b,c=map(int,input().split())
    arr.append((b,c)) i range(m) range m b,c=map(int,input().split()) b map(int,input().split()) map int input().split() ().split () input split c arr.append((b,c)) arr.append arr append (b,c) b c a=sorted(a) a sorted(a) sorted a arr=sorted(arr,key=lambda x:-x[1]) arr sorted(arr,key=lambda x:-x[1]) sorted arr key=lambda x:-x[1] key lambda x:-x[1] -x[1] x[1] x 1 x flag=0 flag 0 left=0 left 0 for tup in arr:
    for i in range(left,min(left+tup[0],n)):
        if tup[1]>a[i]:
            a[i]=tup[1]
        else:
            flag=-1
            break
        if i==n-1:
            flag=-1
            break
    left+=tup[0]
    if flag==-1:
        break tup arr for i in range(left,min(left+tup[0],n)):
        if tup[1]>a[i]:
            a[i]=tup[1]
        else:
            flag=-1
            break
        if i==n-1:
            flag=-1
            break
     i range(left,min(left+tup[0],n)) range left min(left+tup[0],n) min left+tup[0] left tup[0] tup 0 n if tup[1]>a[i]:
            a[i]=tup[1]
        else:
            flag=-1
            break
         tup[1]>a[i] tup[1] tup 1 a[i] a i a[i]=tup[1] a[i] a i tup[1] tup 1 flag=-1 flag -1 break if i==n-1:
            flag=-1
            break
     i==n-1 i n-1 n 1 flag=-1 flag -1 break left+=tup[0] left tup[0] tup 0 if flag==-1:
        break flag==-1 flag -1 break print(sum(a)) print sum(a) sum a arr=sorted(arr,key=lambda x:-x[1]) sorted(arr,key=lambda x:-x[1]) arr b,c=map(int,input().split()) map(int,input().split()) b left+=tup[0] tup[0] left flag=-1 -1 flag left=0 0 left c=map(int,input().split()) map(int,input().split()) c n,m=map(int,input().split()) map(int,input().split()) n m=map(int,input().split()) map(int,input().split()) m flag=0 0 flag flag=-1 -1 flag a=sorted(a) sorted(a) a a=list(map(int,input().split())) list(map(int,input().split())) a arr=[] [] arr
n,m=map(int,input().split())
a=list(map(int,input().split()))
arr=[]

for i in range(m):
    b,c=map(int,input().split())
    arr.append((b,c))

a=sorted(a)
arr=sorted(arr,key=lambda x:-x[1])

flag=0
left=0
for tup in arr:
    for i in range(left,min(left+tup[0],n)):
        if tup[1]>a[i]:
            a[i]=tup[1]
        else:
            flag=-1
            break
        if i==n-1:
            flag=-1
            break
    left+=tup[0]
    if flag==-1:
        break

print(sum(a))