import heapq

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

B,C = [],[]
CB = []

for i in range(m):
    b,c = map(int,input().split())
    B.append(b)
    C.append(c)
    CB.append((c,b))

CB.sort(reverse=True)
for c,b in CB:
    for i in range(b):
        tmp = heapq.heappop(a)
        if tmp >= c:
            heapq.heappush(a,tmp)
            break
        else:
            heapq.heappush(a,c)
print(sum(a)) import heapq heapq 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 B,C = [],[] B [] C [] CB = [] CB [] for i in range(m):
    b,c = map(int,input().split())
    B.append(b)
    C.append(c)
    CB.append((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 B.append(b) B.append B append b C.append(c) C.append C append c CB.append((c,b)) CB.append CB append (c,b) c b CB.sort(reverse=True) CB.sort CB sort reverse=True reverse True for c,b in CB:
    for i in range(b):
        tmp = heapq.heappop(a)
        if tmp >= c:
            heapq.heappush(a,tmp)
            break
        else:
            heapq.heappush(a,c) c b CB for i in range(b):
        tmp = heapq.heappop(a)
        if tmp >= c:
            heapq.heappush(a,tmp)
            break
        else:
            heapq.heappush(a,c) i range(b) range b tmp = heapq.heappop(a) tmp heapq.heappop(a) heapq.heappop heapq heappop a if tmp >= c:
            heapq.heappush(a,tmp)
            break
        else:
            heapq.heappush(a,c) tmp >= c tmp c heapq.heappush(a,tmp) heapq.heappush heapq heappush a tmp break heapq.heappush(a,c) heapq.heappush heapq heappush a c print(sum(a)) print sum(a) sum a a = list(map(int,input().split())) list(map(int,input().split())) a c = map(int,input().split()) map(int,input().split()) c m = map(int,input().split()) map(int,input().split()) m tmp = heapq.heappop(a) heapq.heappop(a) tmp b,c = map(int,input().split()) map(int,input().split()) b CB = [] [] CB B,C = [],[] [] B n,m = map(int,input().split()) map(int,input().split()) n C = [],[] [] C
import heapq

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

B,C = [],[]
CB = []

for i in range(m):
    b,c = map(int,input().split())
    B.append(b)
    C.append(c)
    CB.append((c,b))

CB.sort(reverse=True)
for c,b in CB:
    for i in range(b):
        tmp = heapq.heappop(a)
        if tmp >= c:
            heapq.heappush(a,tmp)
            break
        else:
            heapq.heappush(a,c)
print(sum(a))