import heapq

N, M = map(int, input().split())
A = [int(a) * (-1) for a in input().split()]

B_array = []
for _ in range(M):
    B, C = map(int, input().split())
    B_array.append([C * (-1), B])
B_array.sort()

cnt = 0
i = 0
B_list = []
while cnt < N and i < M:
    B_list.extend([B_array[i][0]] * B_array[i][1])
    cnt += B_array[i][1]
    i += 1

A.extend(B_list)
heapq.heapify(A)

ans = 0
for _ in range(N):
    ans += heapq.heappop(A)
        
print(ans * (-1)) import heapq heapq N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M int(a) * (-1) for a in input().split() for a in input().split() a input().split() ().split () input split for a in input().split() int(a) * (-1) int(a) int a -1 A = [int(a) * (-1) for a in input().split()] A [int(a) * (-1) for a in input().split()] B_array = [] B_array [] for _ in range(M):
    B, C = map(int, input().split())
    B_array.append([C * (-1), B]) _ range(M) range M B, C = map(int, input().split()) B map(int, input().split()) map int input().split() ().split () input split C B_array.append([C * (-1), B]) B_array.append B_array append [C * (-1), B] C * (-1) C -1 B B_array.sort() B_array.sort B_array sort cnt = 0 cnt 0 i = 0 i 0 B_list = [] B_list [] while cnt < N and i < M:
    B_list.extend([B_array[i][0]] * B_array[i][1])
    cnt += B_array[i][1]
    i += 1 cnt < N and i < M cnt < N cnt N i < M i M B_list.extend([B_array[i][0]] * B_array[i][1]) B_list.extend B_list extend [B_array[i][0]] * B_array[i][1] [B_array[i][0]] B_array[i][0] [i] B_array i 0 B_array[i][1] [i] B_array i 1 cnt += B_array[i][1] cnt B_array[i][1] [i] B_array i 1 i += 1 i 1 A.extend(B_list) A.extend A extend B_list heapq.heapify(A) heapq.heapify heapq heapify A ans = 0 ans 0 for _ in range(N):
    ans += heapq.heappop(A)
         _ range(N) range N ans += heapq.heappop(A) ans heapq.heappop(A) heapq.heappop heapq heappop A print(ans * (-1)) print ans * (-1) ans -1 cnt += B_array[i][1] B_array[i][1] cnt B, C = map(int, input().split()) map(int, input().split()) B ans += heapq.heappop(A) heapq.heappop(A) ans cnt = 0 0 cnt i += 1 1 i M = map(int, input().split()) map(int, input().split()) M N, M = map(int, input().split()) map(int, input().split()) N C = map(int, input().split()) map(int, input().split()) C ans = 0 0 ans B_array = [] [] B_array A = [int(a) * (-1) for a in input().split()] [int(a) * (-1) for a in input().split()] A i = 0 0 i B_list = [] [] B_list
import heapq

N, M = map(int, input().split())
A = [int(a) * (-1) for a in input().split()]

B_array = []
for _ in range(M):
    B, C = map(int, input().split())
    B_array.append([C * (-1), B])
B_array.sort()

cnt = 0
i = 0
B_list = []
while cnt < N and i < M:
    B_list.extend([B_array[i][0]] * B_array[i][1])
    cnt += B_array[i][1]
    i += 1

A.extend(B_list)
heapq.heapify(A)

ans = 0
for _ in range(N):
    ans += heapq.heappop(A)
        
print(ans * (-1))