import heapq
n, m = map(int, input().split())
aas = sorted(list(map(int, input().split())))
hq = []
for i in range(m):
    b, c = map(int, input().split())
    heapq.heappush(hq,(-c,b))
i = 0
while hq:
    c, b = heapq.heappop(hq)
    c = -c
    for j in range(i,min(n,i+b)):
        if aas[j] < c:
            aas[j] = c
        else:
            print(sum(aas))
            exit()
    i = j + 1
print(sum(aas)) import heapq heapq n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m aas = sorted(list(map(int, input().split()))) aas sorted(list(map(int, input().split()))) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split hq = [] hq [] for i in range(m):
    b, c = map(int, input().split())
    heapq.heappush(hq,(-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 heapq.heappush(hq,(-c,b)) heapq.heappush heapq heappush hq (-c,b) -c c b i = 0 i 0 while hq:
    c, b = heapq.heappop(hq)
    c = -c
    for j in range(i,min(n,i+b)):
        if aas[j] < c:
            aas[j] = c
        else:
            print(sum(aas))
            exit()
    i = j + 1 hq c, b = heapq.heappop(hq) c heapq.heappop(hq) heapq.heappop heapq heappop hq b c = -c c -c c for j in range(i,min(n,i+b)):
        if aas[j] < c:
            aas[j] = c
        else:
            print(sum(aas))
            exit()
     j range(i,min(n,i+b)) range i min(n,i+b) min n i+b i b if aas[j] < c:
            aas[j] = c
        else:
            print(sum(aas))
            exit()
     aas[j] < c aas[j] aas j c aas[j] = c aas[j] aas j c print(sum(aas)) print sum(aas) sum aas exit() exit i = j + 1 i j + 1 j 1 print(sum(aas)) print sum(aas) sum aas b, c = map(int, input().split()) map(int, input().split()) b i = 0 0 i c = map(int, input().split()) map(int, input().split()) c c, b = heapq.heappop(hq) heapq.heappop(hq) c c = -c -c c hq = [] [] hq i = j + 1 j + 1 i aas = sorted(list(map(int, input().split()))) sorted(list(map(int, input().split()))) aas n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m b = heapq.heappop(hq) heapq.heappop(hq) b
import heapq
n, m = map(int, input().split())
aas = sorted(list(map(int, input().split())))
hq = []
for i in range(m):
    b, c = map(int, input().split())
    heapq.heappush(hq,(-c,b))
i = 0
while hq:
    c, b = heapq.heappop(hq)
    c = -c
    for j in range(i,min(n,i+b)):
        if aas[j] < c:
            aas[j] = c
        else:
            print(sum(aas))
            exit()
    i = j + 1
print(sum(aas))