n,m=map(int,input().split())
a=sorted(map(int,input().split()))
l=list()
for i in range(m):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x:-x[1])
i=0
for b,c in l:
    for j in range(b):
        if i+j<n and a[i+j]<c:
            a[i+j]=c
        else:
            print(sum(a))
            exit()
    i+=b
print(sum(a)) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m a=sorted(map(int,input().split())) a sorted(map(int,input().split())) sorted map(int,input().split()) map int input().split() ().split () input split l=list() l list() list for i in range(m):
    l.append(list(map(int,input().split()))) i range(m) range m l.append(list(map(int,input().split()))) l.append l append list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split l.sort(key=lambda x:-x[1]) l.sort l sort key=lambda x:-x[1] key lambda x:-x[1] -x[1] x[1] x 1 x i=0 i 0 for b,c in l:
    for j in range(b):
        if i+j<n and a[i+j]<c:
            a[i+j]=c
        else:
            print(sum(a))
            exit()
    i+=b b c l for j in range(b):
        if i+j<n and a[i+j]<c:
            a[i+j]=c
        else:
            print(sum(a))
            exit()
     j range(b) range b if i+j<n and a[i+j]<c:
            a[i+j]=c
        else:
            print(sum(a))
            exit()
     i+j<n and a[i+j]<c i+j<n i+j i j n a[i+j]<c a[i+j] a i+j i j c a[i+j]=c a[i+j] a i+j i j c print(sum(a)) print sum(a) sum a exit() exit i+=b i b print(sum(a)) print sum(a) sum a m=map(int,input().split()) map(int,input().split()) m n,m=map(int,input().split()) map(int,input().split()) n l=list() list() l i=0 0 i a=sorted(map(int,input().split())) sorted(map(int,input().split())) a i+=b b i
n,m=map(int,input().split())
a=sorted(map(int,input().split()))
l=list()
for i in range(m):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x:-x[1])
i=0
for b,c in l:
    for j in range(b):
        if i+j<n and a[i+j]<c:
            a[i+j]=c
        else:
            print(sum(a))
            exit()
    i+=b
print(sum(a))