#!/usr/bin/env python3
import heapq

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]

bc = sorted(bc, key=lambda x: x[1], reverse=True)
# print(bc)

heapq.heapify(a)
for b, c in bc:
    for i in range(b):
        num = heapq.heappop(a)
        if num < c:
            heapq.heappush(a, c)
        else:
            heapq.heappush(a, num)
            break
# print(a)
print(sum(a)) import heapq heapq n, m = list(map(int, input().split())) n list(map(int, input().split())) list 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 list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bc = [list(map(int, input().split())) for _ in range(m)] bc [list(map(int, input().split())) for _ in range(m)] bc = sorted(bc, key=lambda x: x[1], reverse=True) bc sorted(bc, key=lambda x: x[1], reverse=True) sorted bc key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True heapq.heapify(a) heapq.heapify heapq heapify a for b, c in bc:
    for i in range(b):
        num = heapq.heappop(a)
        if num < c:
            heapq.heappush(a, c)
        else:
            heapq.heappush(a, num)
            break
# print(a) b c bc for i in range(b):
        num = heapq.heappop(a)
        if num < c:
            heapq.heappush(a, c)
        else:
            heapq.heappush(a, num)
            break
# print(a) i range(b) range b num = heapq.heappop(a) num heapq.heappop(a) heapq.heappop heapq heappop a if num < c:
            heapq.heappush(a, c)
        else:
            heapq.heappush(a, num)
            break
# print(a) num < c num c heapq.heappush(a, c) heapq.heappush heapq heappush a c heapq.heappush(a, num) heapq.heappush heapq heappush a num break print(sum(a)) print sum(a) sum a n, m = list(map(int, input().split())) list(map(int, input().split())) n m = list(map(int, input().split())) list(map(int, input().split())) m bc = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] bc num = heapq.heappop(a) heapq.heappop(a) num a = list(map(int, input().split())) list(map(int, input().split())) a bc = sorted(bc, key=lambda x: x[1], reverse=True) sorted(bc, key=lambda x: x[1], reverse=True) bc
#!/usr/bin/env python3
import heapq

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]

bc = sorted(bc, key=lambda x: x[1], reverse=True)
# print(bc)

heapq.heapify(a)
for b, c in bc:
    for i in range(b):
        num = heapq.heappop(a)
        if num < c:
            heapq.heappush(a, c)
        else:
            heapq.heappush(a, num)
            break
# print(a)
print(sum(a))
