n , m = map(int, input().split())
a = list(map(int,input().split()))
a.sort()
bc=[]
for i in range(m):
    b , c = map(int, input().split())
    bc.append((b,c))
bc.sort(key = lambda x : x[1],reverse=True)

t=0
for i in range(m):
    b,c=bc[i]
    if t>=n:
        break
    if a[t]>=c:
        break
    for j in range(b):
        if a[t]<c:
            a[t]=c
            if t<n-1:
                t+=1
        else:
            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 a.sort() a.sort a sort bc=[] bc [] for i in range(m):
    b , c = map(int, input().split())
    bc.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 bc.append((b,c)) bc.append bc append (b,c) b c bc.sort(key = lambda x : x[1],reverse=True) bc.sort bc sort key = lambda x : x[1] key lambda x : x[1] x[1] x 1 x reverse=True reverse True t=0 t 0 for i in range(m):
    b,c=bc[i]
    if t>=n:
        break
    if a[t]>=c:
        break
    for j in range(b):
        if a[t]<c:
            a[t]=c
            if t<n-1:
                t+=1
        else:
            break i range(m) range m b,c=bc[i] b bc[i] bc i c if t>=n:
        break
     t>=n t n break if a[t]>=c:
        break
     a[t]>=c a[t] a t c break for j in range(b):
        if a[t]<c:
            a[t]=c
            if t<n-1:
                t+=1
        else:
            break j range(b) range b if a[t]<c:
            a[t]=c
            if t<n-1:
                t+=1
        else:
            break a[t]<c a[t] a t c a[t]=c a[t] a t c if t<n-1:
                t+=1
         t<n-1 t n-1 n 1 t+=1 t 1 break print(sum(a)) print sum(a) sum a bc=[] [] bc t+=1 1 t m = map(int, input().split()) map(int, input().split()) m c = map(int, input().split()) map(int, input().split()) c t=0 0 t b,c=bc[i] bc[i] b n , m = map(int, input().split()) map(int, input().split()) n a = list(map(int,input().split())) list(map(int,input().split())) a c=bc[i] bc[i] c b , c = map(int, input().split()) map(int, input().split()) b
n , m = map(int, input().split())
a = list(map(int,input().split()))
a.sort()
bc=[]
for i in range(m):
    b , c = map(int, input().split())
    bc.append((b,c))
bc.sort(key = lambda x : x[1],reverse=True)

t=0
for i in range(m):
    b,c=bc[i]
    if t>=n:
        break
    if a[t]>=c:
        break
    for j in range(b):
        if a[t]<c:
            a[t]=c
            if t<n-1:
                t+=1
        else:
            break
print(sum(a))
