n, m  = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cb = []
for i in range(m):
  b, c = map(int, input().split())
  cb.append([c,b])
cb.sort(reverse=True)

j = 0
for i in range(m):
  k = 0
  while k<cb[i][1] and k+j<n and a[k+j]<cb[i][0]:
    a[k+j] = cb[i][0]
    k += 1
  j += k
  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 a.sort() a.sort a sort cb = [] cb [] for i in range(m):
  b, c = map(int, input().split())
  cb.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 cb.append([c,b]) cb.append cb append [c,b] c b cb.sort(reverse=True) cb.sort cb sort reverse=True reverse True j = 0 j 0 for i in range(m):
  k = 0
  while k<cb[i][1] and k+j<n and a[k+j]<cb[i][0]:
    a[k+j] = cb[i][0]
    k += 1
  j += k
  if j == n:
    break
     i range(m) range m k = 0 k 0 while k<cb[i][1] and k+j<n and a[k+j]<cb[i][0]:
    a[k+j] = cb[i][0]
    k += 1
   k<cb[i][1] and k+j<n and a[k+j]<cb[i][0] k<cb[i][1] and k+j<n k<cb[i][1] k cb[i][1] [i] cb i 1 k+j<n k+j k j n a[k+j]<cb[i][0] a[k+j] a k+j k j cb[i][0] [i] cb i 0 a[k+j] = cb[i][0] a[k+j] a k+j k j cb[i][0] [i] cb i 0 k += 1 k 1 j += k j k if j == n:
    break
     j == n j n break print(sum(a)) print sum(a) sum a n, m  = map(int, input().split()) map(int, input().split()) n m  = map(int, input().split()) map(int, input().split()) m j += k k j cb = [] [] cb c = map(int, input().split()) map(int, input().split()) c k = 0 0 k j = 0 0 j a = list(map(int, input().split())) list(map(int, input().split())) a k += 1 1 k b, c = map(int, input().split()) map(int, input().split()) b
n, m  = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cb = []
for i in range(m):
  b, c = map(int, input().split())
  cb.append([c,b])
cb.sort(reverse=True)

j = 0
for i in range(m):
  k = 0
  while k<cb[i][1] and k+j<n and a[k+j]<cb[i][0]:
    a[k+j] = cb[i][0]
    k += 1
  j += k
  if j == n:
    break
    
print(sum(a))