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

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

change.sort(reverse=True)
elem=0

for c, b in change:
    while elem<n and b>0:
        if a[elem]<c:
            a[elem]=c
            b-=1
        elem+=1

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 a.sort() a.sort a sort change=[] change [] for i in range(m):
    b, c=map(int, input().split())
    change.append((c, b)) i range(m) range m b, c=map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c change.append((c, b)) change.append change append (c, b) c b change.sort(reverse=True) change.sort change sort reverse=True reverse True elem=0 elem 0 for c, b in change:
    while elem<n and b>0:
        if a[elem]<c:
            a[elem]=c
            b-=1
        elem+=1 c b change while elem<n and b>0:
        if a[elem]<c:
            a[elem]=c
            b-=1
        elem+=1 elem<n and b>0 elem<n elem n b>0 b 0 if a[elem]<c:
            a[elem]=c
            b-=1
         a[elem]<c a[elem] a elem c a[elem]=c a[elem] a elem c b-=1 b 1 elem+=1 elem 1 print(sum(a)) print sum(a) sum a n, m=map(int, input().split()) map(int, input().split()) n a=list(map(int, input().split())) list(map(int, input().split())) a elem+=1 1 elem b, c=map(int, input().split()) map(int, input().split()) b c=map(int, input().split()) map(int, input().split()) c change=[] [] change b-=1 1 b m=map(int, input().split()) map(int, input().split()) m elem=0 0 elem
n, m=map(int, input().split())
a=list(map(int, input().split()))
a.sort()
change=[]

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

change.sort(reverse=True)
elem=0

for c, b in change:
    while elem<n and b>0:
        if a[elem]<c:
            a[elem]=c
            b-=1
        elem+=1

print(sum(a))