import heapq
N,M=map(int,input().split())
A=list(map(int,input().split()))
heapq.heapify(A)
numbers=[]
for _ in range(M):
    B,C=map(int,input().split())
    numbers.append([C,B])
numbers=sorted(numbers,reverse=True)
for number in numbers:
    B=number[1]
    C=number[0]
    for _ in range(B):
        a = heapq.heappop(A)
        if C <= a:
            heapq.heappush(A, a)
            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 numbers=[] numbers [] for _ in range(M):
    B,C=map(int,input().split())
    numbers.append([C,B]) _ range(M) range M B,C=map(int,input().split()) B map(int,input().split()) map int input().split() ().split () input split C numbers.append([C,B]) numbers.append numbers append [C,B] C B numbers=sorted(numbers,reverse=True) numbers sorted(numbers,reverse=True) sorted numbers reverse=True reverse True for number in numbers:
    B=number[1]
    C=number[0]
    for _ in range(B):
        a = heapq.heappop(A)
        if C <= a:
            heapq.heappush(A, a)
            break
        else:
            heapq.heappush(A,C) number numbers B=number[1] B number[1] number 1 C=number[0] C number[0] number 0 for _ in range(B):
        a = heapq.heappop(A)
        if C <= a:
            heapq.heappush(A, a)
            break
        else:
            heapq.heappush(A,C) _ range(B) range B a = heapq.heappop(A) a heapq.heappop(A) heapq.heappop heapq heappop A if C <= a:
            heapq.heappush(A, a)
            break
        else:
            heapq.heappush(A,C) C <= a C a heapq.heappush(A, a) heapq.heappush heapq heappush A a break heapq.heappush(A,C) heapq.heappush heapq heappush A C print(sum(A)) print sum(A) sum A M=map(int,input().split()) map(int,input().split()) M N,M=map(int,input().split()) map(int,input().split()) N B=number[1] number[1] B a = heapq.heappop(A) heapq.heappop(A) a A=list(map(int,input().split())) list(map(int,input().split())) A C=map(int,input().split()) map(int,input().split()) C numbers=sorted(numbers,reverse=True) sorted(numbers,reverse=True) numbers numbers=[] [] numbers C=number[0] number[0] C B,C=map(int,input().split()) map(int,input().split()) B
import heapq
N,M=map(int,input().split())
A=list(map(int,input().split()))
heapq.heapify(A)
numbers=[]
for _ in range(M):
    B,C=map(int,input().split())
    numbers.append([C,B])
numbers=sorted(numbers,reverse=True)
for number in numbers:
    B=number[1]
    C=number[0]
    for _ in range(B):
        a = heapq.heappop(A)
        if C <= a:
            heapq.heappush(A, a)
            break
        else:
            heapq.heappush(A,C)
print(sum(A))
