import sys
import heapq
input = sys.stdin.readline

n,m = map(int,input().split())
A = list(map(int,input().split()))
heapq.heapify(A)

BC = [list(map(int, input().split())) for i in range(m)]
BC = sorted(BC,key = lambda x:-x[1])

for b,c in BC:
    for i in range(b):
        a = heapq.heappop(A)
        if a < c:
            heapq.heappush(A,c)
        else:
            heapq.heappush(A,a)
            break
print(sum(A)) import sys sys import heapq heapq input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline 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 heapq.heapify(A) heapq.heapify heapq heapify A list(map(int, input().split())) for i in range(m) for i in range(m) i range(m) range m for i 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 i in range(m)] BC [list(map(int, input().split())) for i in range(m)] BC = sorted(BC,key = lambda x:-x[1]) BC sorted(BC,key = lambda x:-x[1]) sorted BC key = lambda x:-x[1] key lambda x:-x[1] -x[1] x[1] x 1 x for b,c in BC:
    for i in range(b):
        a = heapq.heappop(A)
        if a < c:
            heapq.heappush(A,c)
        else:
            heapq.heappush(A,a)
            break b c BC for i in range(b):
        a = heapq.heappop(A)
        if a < c:
            heapq.heappush(A,c)
        else:
            heapq.heappush(A,a)
            break i range(b) range b a = heapq.heappop(A) a heapq.heappop(A) heapq.heappop heapq heappop A if a < c:
            heapq.heappush(A,c)
        else:
            heapq.heappush(A,a)
            break a < c a c heapq.heappush(A,c) heapq.heappush heapq heappush A c heapq.heappush(A,a) heapq.heappush heapq heappush A a break print(sum(A)) print sum(A) sum A BC = [list(map(int, input().split())) for i in range(m)] [list(map(int, input().split())) for i in range(m)] BC BC = sorted(BC,key = lambda x:-x[1]) sorted(BC,key = lambda x:-x[1]) BC m = map(int,input().split()) map(int,input().split()) m n,m = map(int,input().split()) map(int,input().split()) n input = sys.stdin.readline sys.stdin.readline input a = heapq.heappop(A) heapq.heappop(A) a A = list(map(int,input().split())) list(map(int,input().split())) A
import sys
import heapq
input = sys.stdin.readline

n,m = map(int,input().split())
A = list(map(int,input().split()))
heapq.heapify(A)

BC = [list(map(int, input().split())) for i in range(m)]
BC = sorted(BC,key = lambda x:-x[1])

for b,c in BC:
    for i in range(b):
        a = heapq.heappop(A)
        if a < c:
            heapq.heappush(A,c)
        else:
            heapq.heappush(A,a)
            break
print(sum(A))