from operator import itemgetter
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
data = []
now = 0
for i in range(m):
    b,c = map(int,input().split())
    data.append((b,c))
for i,j in sorted(data,key=itemgetter(1),reverse=True):
    while A[now] < j and i:
        A[now] = j
        i -= 1
        now += 1
        if now == n:
            print(sum(A))
            exit()
    if A[now] >= j:
        print(sum(A))
        break
else:
    print(sum(A))         from operator import itemgetter 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 data = [] data [] now = 0 now 0 for i in range(m):
    b,c = map(int,input().split())
    data.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 data.append((b,c)) data.append data append (b,c) b c for i,j in sorted(data,key=itemgetter(1),reverse=True):
    while A[now] < j and i:
        A[now] = j
        i -= 1
        now += 1
        if now == n:
            print(sum(A))
            exit()
    if A[now] >= j:
        print(sum(A))
        break
else:
    print(sum(A))         i j sorted(data,key=itemgetter(1),reverse=True) sorted data key=itemgetter(1) key itemgetter(1) itemgetter 1 reverse=True reverse True while A[now] < j and i:
        A[now] = j
        i -= 1
        now += 1
        if now == n:
            print(sum(A))
            exit()
     A[now] < j and i A[now] < j A[now] A now j i A[now] = j A[now] A now j i -= 1 i 1 now += 1 now 1 if now == n:
            print(sum(A))
            exit()
     now == n now n print(sum(A)) print sum(A) sum A exit() exit if A[now] >= j:
        print(sum(A))
        break A[now] >= j A[now] A now j print(sum(A)) print sum(A) sum A break print(sum(A)) print sum(A) sum A n,m = map(int,input().split()) map(int,input().split()) n i -= 1 1 i c = map(int,input().split()) map(int,input().split()) c A = list(map(int,input().split())) list(map(int,input().split())) A b,c = map(int,input().split()) map(int,input().split()) b now += 1 1 now now = 0 0 now m = map(int,input().split()) map(int,input().split()) m data = [] [] data
from operator import itemgetter
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
data = []
now = 0
for i in range(m):
    b,c = map(int,input().split())
    data.append((b,c))
for i,j in sorted(data,key=itemgetter(1),reverse=True):
    while A[now] < j and i:
        A[now] = j
        i -= 1
        now += 1
        if now == n:
            print(sum(A))
            exit()
    if A[now] >= j:
        print(sum(A))
        break
else:
    print(sum(A))        