N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

cards = []
for _ in range(M):
  b,c = map(int,input().split())
  cards.append([c,b])
cards.sort(key=lambda x: -x[0])

res = 0
idx = 0
left = cards[idx][1]
for i,a in enumerate(A):
  if a > cards[idx][0]:
    res += sum(A[i:])
    break
  else:
    res += cards[idx][0]

    left -= 1
    if left <= 0:
      idx += 1
      if idx >= M:
        if i+1 < N:
          res += sum(A[i+1:])
        break
      else:
        left = cards[idx][1]

print(res) 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 cards = [] cards [] for _ in range(M):
  b,c = map(int,input().split())
  cards.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 cards.append([c,b]) cards.append cards append [c,b] c b cards.sort(key=lambda x: -x[0]) cards.sort cards sort key=lambda x: -x[0] key lambda x: -x[0] -x[0] x[0] x 0 x res = 0 res 0 idx = 0 idx 0 left = cards[idx][1] left cards[idx][1] [idx] cards idx 1 for i,a in enumerate(A):
  if a > cards[idx][0]:
    res += sum(A[i:])
    break
  else:
    res += cards[idx][0]

    left -= 1
    if left <= 0:
      idx += 1
      if idx >= M:
        if i+1 < N:
          res += sum(A[i+1:])
        break
      else:
        left = cards[idx][1] i a enumerate(A) enumerate A if a > cards[idx][0]:
    res += sum(A[i:])
    break
  else:
    res += cards[idx][0]

    left -= 1
    if left <= 0:
      idx += 1
      if idx >= M:
        if i+1 < N:
          res += sum(A[i+1:])
        break
      else:
        left = cards[idx][1] a > cards[idx][0] a cards[idx][0] [idx] cards idx 0 res += sum(A[i:]) res sum(A[i:]) sum A[i:] A i: i break res += cards[idx][0] res cards[idx][0] [idx] cards idx 0 left -= 1 left 1 if left <= 0:
      idx += 1
      if idx >= M:
        if i+1 < N:
          res += sum(A[i+1:])
        break
      else:
        left = cards[idx][1] left <= 0 left 0 idx += 1 idx 1 if idx >= M:
        if i+1 < N:
          res += sum(A[i+1:])
        break
      else:
        left = cards[idx][1] idx >= M idx M if i+1 < N:
          res += sum(A[i+1:])
         i+1 < N i+1 i 1 N res += sum(A[i+1:]) res sum(A[i+1:]) sum A[i+1:] A i+1: i+1 i 1 break left = cards[idx][1] left cards[idx][1] [idx] cards idx 1 print(res) print res left = cards[idx][1] cards[idx][1] left cards = [] [] cards left = cards[idx][1] cards[idx][1] left b,c = map(int,input().split()) map(int,input().split()) b N,M = map(int,input().split()) map(int,input().split()) N idx += 1 1 idx res += sum(A[i:]) sum(A[i:]) res res = 0 0 res res += sum(A[i+1:]) sum(A[i+1:]) res c = map(int,input().split()) map(int,input().split()) c A = list(map(int,input().split())) list(map(int,input().split())) A left -= 1 1 left res += cards[idx][0] cards[idx][0] res M = map(int,input().split()) map(int,input().split()) M idx = 0 0 idx
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

cards = []
for _ in range(M):
  b,c = map(int,input().split())
  cards.append([c,b])
cards.sort(key=lambda x: -x[0])

res = 0
idx = 0
left = cards[idx][1]
for i,a in enumerate(A):
  if a > cards[idx][0]:
    res += sum(A[i:])
    break
  else:
    res += cards[idx][0]

    left -= 1
    if left <= 0:
      idx += 1
      if idx >= M:
        if i+1 < N:
          res += sum(A[i+1:])
        break
      else:
        left = cards[idx][1]

print(res)