import numpy as np
n, m = map(int, input().split())
a = list(map(int, input().split()))
flag = False
c = []
for _ in range(m):
  x,y = map(int, input().split())
  c.append([x,y])
c = np.array(c)
e = c[np.argsort(c[:, 1])]
d = []
for x,y in reversed(e):
  for i in range(x):
    d.append(y)
    if len(d) == n:
      flag = True
      break
  if flag:
    break
f = sorted(a+d,reverse=True)
print(sum(f[:n])) import numpy as np numpy 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 flag = False flag False c = [] c [] for _ in range(m):
  x,y = map(int, input().split())
  c.append([x,y]) _ range(m) range m x,y = map(int, input().split()) x map(int, input().split()) map int input().split() ().split () input split y c.append([x,y]) c.append c append [x,y] x y c = np.array(c) c np.array(c) np.array np array c e = c[np.argsort(c[:, 1])] e c[np.argsort(c[:, 1])] c np.argsort(c[:, 1]) np.argsort np argsort c[:, 1] c : d = [] d [] for x,y in reversed(e):
  for i in range(x):
    d.append(y)
    if len(d) == n:
      flag = True
      break
  if flag:
    break x y reversed(e) reversed e for i in range(x):
    d.append(y)
    if len(d) == n:
      flag = True
      break
   i range(x) range x d.append(y) d.append d append y if len(d) == n:
      flag = True
      break
   len(d) == n len(d) len d n flag = True flag True break if flag:
    break flag break f = sorted(a+d,reverse=True) f sorted(a+d,reverse=True) sorted a+d a d reverse=True reverse True print(sum(f[:n])) print sum(f[:n]) sum f[:n] f :n n e = c[np.argsort(c[:, 1])] c[np.argsort(c[:, 1])] e f = sorted(a+d,reverse=True) sorted(a+d,reverse=True) f n, m = map(int, input().split()) map(int, input().split()) n x,y = map(int, input().split()) map(int, input().split()) x flag = True True flag flag = False False flag y = map(int, input().split()) map(int, input().split()) y c = np.array(c) np.array(c) c m = map(int, input().split()) map(int, input().split()) m d = [] [] d c = [] [] c a = list(map(int, input().split())) list(map(int, input().split())) a
import numpy as np
n, m = map(int, input().split())
a = list(map(int, input().split()))
flag = False
c = []
for _ in range(m):
  x,y = map(int, input().split())
  c.append([x,y])
c = np.array(c)
e = c[np.argsort(c[:, 1])]
d = []
for x,y in reversed(e):
  for i in range(x):
    d.append(y)
    if len(d) == n:
      flag = True
      break
  if flag:
    break
f = sorted(a+d,reverse=True)
print(sum(f[:n]))