N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for i in range(M):
  tmp = list(map(int, input().split()))
  BC.append(tmp)

A.sort()
BC.sort(key=lambda x: x[1], reverse=True)

j = 0
for i in range(M):
  count = 0
  while A[j] < BC[i][1]:
    A[j] = BC[i][1]			# 値を置き換える
    j += 1
    count += 1
    if count == BC[i][0] or j == N:
      break
  if j == N:
    break
print(sum(A)) 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 BC = [] BC [] for i in range(M):
  tmp = list(map(int, input().split()))
  BC.append(tmp) i range(M) range M tmp = list(map(int, input().split())) tmp list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split BC.append(tmp) BC.append BC append tmp A.sort() A.sort A sort 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 j = 0 j 0 for i in range(M):
  count = 0
  while A[j] < BC[i][1]:
    A[j] = BC[i][1]			# 値を置き換える
    j += 1
    count += 1
    if count == BC[i][0] or j == N:
      break
  if j == N:
    break i range(M) range M count = 0 count 0 while A[j] < BC[i][1]:
    A[j] = BC[i][1]			# 値を置き換える
    j += 1
    count += 1
    if count == BC[i][0] or j == N:
      break
   A[j] < BC[i][1] A[j] A j BC[i][1] [i] BC i 1 A[j] = BC[i][1] A[j] A j BC[i][1] [i] BC i 1 j += 1 j 1 count += 1 count 1 if count == BC[i][0] or j == N:
      break
   count == BC[i][0] or j == N count == BC[i][0] count BC[i][0] [i] BC i 0 j == N j N break if j == N:
    break j == N j N break print(sum(A)) print sum(A) sum A j = 0 0 j M = map(int, input().split()) map(int, input().split()) M A = list(map(int, input().split())) list(map(int, input().split())) A BC = [] [] BC tmp = list(map(int, input().split())) list(map(int, input().split())) tmp count += 1 1 count N, M = map(int, input().split()) map(int, input().split()) N count = 0 0 count j += 1 1 j
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for i in range(M):
  tmp = list(map(int, input().split()))
  BC.append(tmp)

A.sort()
BC.sort(key=lambda x: x[1], reverse=True)

j = 0
for i in range(M):
  count = 0
  while A[j] < BC[i][1]:
    A[j] = BC[i][1]			# 値を置き換える
    j += 1
    count += 1
    if count == BC[i][0] or j == N:
      break
  if j == N:
    break
print(sum(A))