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


import heapq
aa = a.copy()
heapq.heapify(aa)

f = False
bc.sort(key=lambda x:x[1], reverse=True)
for b, c in bc:
    for _ in range(b):
        x = heapq.heappop(aa)
        if x < c:
            heapq.heappush(aa, c)
        else:
            heapq.heappush(aa, x)
            f = True
            break
    if f:
        break

print(sum(aa)) 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 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)] import heapq heapq aa = a.copy() aa a.copy() a.copy a copy heapq.heapify(aa) heapq.heapify heapq heapify aa f = False f False 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 for b, c in bc:
    for _ in range(b):
        x = heapq.heappop(aa)
        if x < c:
            heapq.heappush(aa, c)
        else:
            heapq.heappush(aa, x)
            f = True
            break
    if f:
        break b c bc for _ in range(b):
        x = heapq.heappop(aa)
        if x < c:
            heapq.heappush(aa, c)
        else:
            heapq.heappush(aa, x)
            f = True
            break
     _ range(b) range b x = heapq.heappop(aa) x heapq.heappop(aa) heapq.heappop heapq heappop aa if x < c:
            heapq.heappush(aa, c)
        else:
            heapq.heappush(aa, x)
            f = True
            break
     x < c x c heapq.heappush(aa, c) heapq.heappush heapq heappush aa c heapq.heappush(aa, x) heapq.heappush heapq heappush aa x f = True f True break if f:
        break f break print(sum(aa)) print sum(aa) sum aa m = map(int, input().split()) 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 f = False False f x = heapq.heappop(aa) heapq.heappop(aa) x n, m = map(int, input().split()) map(int, input().split()) n f = True True f a = list(map(int, input().split())) list(map(int, input().split())) a aa = a.copy() a.copy() aa
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for _ in range(m)]


import heapq
aa = a.copy()
heapq.heapify(aa)

f = False
bc.sort(key=lambda x:x[1], reverse=True)
for b, c in bc:
    for _ in range(b):
        x = heapq.heappop(aa)
        if x < c:
            heapq.heappush(aa, c)
        else:
            heapq.heappush(aa, x)
            f = True
            break
    if f:
        break

print(sum(aa))
