N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
B = []
for i in range(M):
  b, c = map(int, input().split())
  B.append([c, b])
B.sort(reverse=True)
i = 0
f = 0
for j in range(M):
  while B[j][1]:
    if A[i] < B[j][0]:
      A[i] = B[j][0]
      B[j][1] -= 1
      i += 1
      if i >= N:
        f = 1
        break
    else:
      f = 1
      break
  if f == 1:
    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 A.sort() A.sort A sort B = [] B [] for i in range(M):
  b, c = map(int, input().split())
  B.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([c, b]) B.append B append [c, b] c b B.sort(reverse=True) B.sort B sort reverse=True reverse True i = 0 i 0 f = 0 f 0 for j in range(M):
  while B[j][1]:
    if A[i] < B[j][0]:
      A[i] = B[j][0]
      B[j][1] -= 1
      i += 1
      if i >= N:
        f = 1
        break
    else:
      f = 1
      break
  if f == 1:
    break j range(M) range M while B[j][1]:
    if A[i] < B[j][0]:
      A[i] = B[j][0]
      B[j][1] -= 1
      i += 1
      if i >= N:
        f = 1
        break
    else:
      f = 1
      break
   B[j][1] [j] B j 1 if A[i] < B[j][0]:
      A[i] = B[j][0]
      B[j][1] -= 1
      i += 1
      if i >= N:
        f = 1
        break
    else:
      f = 1
      break
   A[i] < B[j][0] A[i] A i B[j][0] [j] B j 0 A[i] = B[j][0] A[i] A i B[j][0] [j] B j 0 B[j][1] -= 1 B[j][1] [j] B j 1 1 i += 1 i 1 if i >= N:
        f = 1
        break
     i >= N i N f = 1 f 1 break f = 1 f 1 break if f == 1:
    break f == 1 f 1 break print(sum(A)) print sum(A) sum A i += 1 1 i M = map(int, input().split()) map(int, input().split()) M i = 0 0 i B = [] [] B b, c = map(int, input().split()) map(int, input().split()) b f = 1 1 f f = 0 0 f c = map(int, input().split()) map(int, input().split()) c A = list(map(int, input().split())) list(map(int, input().split())) A f = 1 1 f N, M = map(int, input().split()) map(int, input().split()) N
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
B = []
for i in range(M):
  b, c = map(int, input().split())
  B.append([c, b])
B.sort(reverse=True)
i = 0
f = 0
for j in range(M):
  while B[j][1]:
    if A[i] < B[j][0]:
      A[i] = B[j][0]
      B[j][1] -= 1
      i += 1
      if i >= N:
        f = 1
        break
    else:
      f = 1
      break
  if f == 1:
    break
print(sum(A))