N, M = map(int, input().split())

As = [0] + list(map(int, input().split()))
As.sort(reverse=True)
BCs = [(0,0)]

memo = [0]*N

for _ in range(M):
  b,c = map(int, input().split())
  BCs.append((b,c))
  
BCs.sort(key=lambda x:x[1], reverse=True)

cnt = 0
rlt = 0
i = 0
j = 0
while cnt < N:
  if As[i] >= BCs[j][1]:
    rlt += As[i]
    cnt += 1
    i += 1
  else:
    if cnt + BCs[j][0] < N:
      rlt += BCs[j][0]*BCs[j][1]
      cnt += BCs[j][0]
      j += 1
    else:
      rlt += (N-cnt)*BCs[j][1]
      break
  
print(rlt) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M As = [0] + list(map(int, input().split())) As [0] + list(map(int, input().split())) [0] 0 list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split As.sort(reverse=True) As.sort As sort reverse=True reverse True BCs = [(0,0)] BCs [(0,0)] (0,0) 0 0 memo = [0]*N memo [0]*N [0] 0 N for _ in range(M):
  b,c = map(int, input().split())
  BCs.append((b,c))
   _ range(M) range M b,c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c BCs.append((b,c)) BCs.append BCs append (b,c) b c BCs.sort(key=lambda x:x[1], reverse=True) BCs.sort BCs sort key=lambda x:x[1] key lambda x:x[1] x[1] x 1 x reverse=True reverse True cnt = 0 cnt 0 rlt = 0 rlt 0 i = 0 i 0 j = 0 j 0 while cnt < N:
  if As[i] >= BCs[j][1]:
    rlt += As[i]
    cnt += 1
    i += 1
  else:
    if cnt + BCs[j][0] < N:
      rlt += BCs[j][0]*BCs[j][1]
      cnt += BCs[j][0]
      j += 1
    else:
      rlt += (N-cnt)*BCs[j][1]
      break
   cnt < N cnt N if As[i] >= BCs[j][1]:
    rlt += As[i]
    cnt += 1
    i += 1
  else:
    if cnt + BCs[j][0] < N:
      rlt += BCs[j][0]*BCs[j][1]
      cnt += BCs[j][0]
      j += 1
    else:
      rlt += (N-cnt)*BCs[j][1]
      break
   As[i] >= BCs[j][1] As[i] As i BCs[j][1] [j] BCs j 1 rlt += As[i] rlt As[i] As i cnt += 1 cnt 1 i += 1 i 1 if cnt + BCs[j][0] < N:
      rlt += BCs[j][0]*BCs[j][1]
      cnt += BCs[j][0]
      j += 1
    else:
      rlt += (N-cnt)*BCs[j][1]
      break
   cnt + BCs[j][0] < N cnt + BCs[j][0] cnt BCs[j][0] [j] BCs j 0 N rlt += BCs[j][0]*BCs[j][1] rlt BCs[j][0]*BCs[j][1] BCs[j][0] [j] BCs j 0 BCs[j][1] [j] BCs j 1 cnt += BCs[j][0] cnt BCs[j][0] [j] BCs j 0 j += 1 j 1 rlt += (N-cnt)*BCs[j][1] rlt (N-cnt)*BCs[j][1] N-cnt N cnt BCs[j][1] [j] BCs j 1 break print(rlt) print rlt As = [0] + list(map(int, input().split())) [0] + list(map(int, input().split())) As rlt += BCs[j][0]*BCs[j][1] BCs[j][0]*BCs[j][1] rlt i = 0 0 i BCs = [(0,0)] [(0,0)] BCs j = 0 0 j rlt = 0 0 rlt i += 1 1 i j += 1 1 j N, M = map(int, input().split()) map(int, input().split()) N rlt += As[i] As[i] rlt b,c = map(int, input().split()) map(int, input().split()) b rlt += (N-cnt)*BCs[j][1] (N-cnt)*BCs[j][1] rlt M = map(int, input().split()) map(int, input().split()) M c = map(int, input().split()) map(int, input().split()) c cnt += 1 1 cnt memo = [0]*N [0]*N memo cnt += BCs[j][0] BCs[j][0] cnt cnt = 0 0 cnt
N, M = map(int, input().split())

As = [0] + list(map(int, input().split()))
As.sort(reverse=True)
BCs = [(0,0)]

memo = [0]*N

for _ in range(M):
  b,c = map(int, input().split())
  BCs.append((b,c))
  
BCs.sort(key=lambda x:x[1], reverse=True)

cnt = 0
rlt = 0
i = 0
j = 0
while cnt < N:
  if As[i] >= BCs[j][1]:
    rlt += As[i]
    cnt += 1
    i += 1
  else:
    if cnt + BCs[j][0] < N:
      rlt += BCs[j][0]*BCs[j][1]
      cnt += BCs[j][0]
      j += 1
    else:
      rlt += (N-cnt)*BCs[j][1]
      break
  
print(rlt)