from collections import defaultdict
n,m=map(int,input().split())
a=list(map(int,input().split()))
d=defaultdict(int)
a.sort()

for i in range(m):
    b,c=map(int,input().split())
    d[c]+=b

d_sorted=sorted(d.items(),reverse=True, key=lambda x:x[0])
l=[]

for i,j in d_sorted:
    for k in range(j):
        l.append(i)
        if len(l)>n:
            break
    else:
        continue
    break
for i in range(min(n, len(l))):
    a[i]=max(a[i],l[i])

print(sum(a)) from collections import defaultdict 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 d=defaultdict(int) d defaultdict(int) defaultdict int a.sort() a.sort a sort for i in range(m):
    b,c=map(int,input().split())
    d[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 d[c]+=b d[c] d c b d_sorted=sorted(d.items(),reverse=True, key=lambda x:x[0]) d_sorted sorted(d.items(),reverse=True, key=lambda x:x[0]) sorted d.items() d.items d items reverse=True reverse True key=lambda x:x[0] key lambda x:x[0] x[0] x 0 x l=[] l [] for i,j in d_sorted:
    for k in range(j):
        l.append(i)
        if len(l)>n:
            break
    else:
        continue
    break i j d_sorted for k in range(j):
        l.append(i)
        if len(l)>n:
            break
    else:
        continue
     k range(j) range j l.append(i) l.append l append i if len(l)>n:
            break
     len(l)>n len(l) len l n break continue break for i in range(min(n, len(l))):
    a[i]=max(a[i],l[i]) i range(min(n, len(l))) range min(n, len(l)) min n len(l) len l a[i]=max(a[i],l[i]) a[i] a i max(a[i],l[i]) max a[i] a i l[i] l i print(sum(a)) print sum(a) sum a n,m=map(int,input().split()) map(int,input().split()) n d_sorted=sorted(d.items(),reverse=True, key=lambda x:x[0]) sorted(d.items(),reverse=True, key=lambda x:x[0]) d_sorted m=map(int,input().split()) map(int,input().split()) m b,c=map(int,input().split()) map(int,input().split()) b a=list(map(int,input().split())) list(map(int,input().split())) a d=defaultdict(int) defaultdict(int) d c=map(int,input().split()) map(int,input().split()) c l=[] [] l
from collections import defaultdict
n,m=map(int,input().split())
a=list(map(int,input().split()))
d=defaultdict(int)
a.sort()

for i in range(m):
    b,c=map(int,input().split())
    d[c]+=b

d_sorted=sorted(d.items(),reverse=True, key=lambda x:x[0])
l=[]

for i,j in d_sorted:
    for k in range(j):
        l.append(i)
        if len(l)>n:
            break
    else:
        continue
    break
for i in range(min(n, len(l))):
    a[i]=max(a[i],l[i])

print(sum(a))