n, m = map(int, input().split())
a = [int(i) for i in input().split()]
a = sorted(a)

l = []
for i in range(m):
  l.append(list(map(int, input().split())))
  
l = sorted(l, reverse=True, key=lambda x: x[1])

b = []
for _ in range(n):
  b.append(l[0][1])
  l[0][0] -= 1
  if l[0][0] == 0:
    l.pop(0)
  if l == []:
    break

for i in range(len(b)):
  if a[i] < b[i]:
    a[i] = b[i]
  else:
    break
    
print(sum(a)) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a = [int(i) for i in input().split()] a [int(i) for i in input().split()] a = sorted(a) a sorted(a) sorted a l = [] l [] for i in range(m):
  l.append(list(map(int, input().split())))
   i range(m) range m l.append(list(map(int, input().split()))) l.append l append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split l = sorted(l, reverse=True, key=lambda x: x[1]) l sorted(l, reverse=True, key=lambda x: x[1]) sorted l reverse=True reverse True key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x b = [] b [] for _ in range(n):
  b.append(l[0][1])
  l[0][0] -= 1
  if l[0][0] == 0:
    l.pop(0)
  if l == []:
    break _ range(n) range n b.append(l[0][1]) b.append b append l[0][1] [0] l 0 1 l[0][0] -= 1 l[0][0] [0] l 0 0 1 if l[0][0] == 0:
    l.pop(0)
   l[0][0] == 0 l[0][0] [0] l 0 0 0 l.pop(0) l.pop l pop 0 if l == []:
    break l == [] l [] break for i in range(len(b)):
  if a[i] < b[i]:
    a[i] = b[i]
  else:
    break
     i range(len(b)) range len(b) len b if a[i] < b[i]:
    a[i] = b[i]
  else:
    break
     a[i] < b[i] a[i] a i b[i] b i a[i] = b[i] a[i] a i b[i] b i break print(sum(a)) print sum(a) sum a b = [] [] b m = map(int, input().split()) map(int, input().split()) m a = [int(i) for i in input().split()] [int(i) for i in input().split()] a l = [] [] l a = sorted(a) sorted(a) a n, m = map(int, input().split()) map(int, input().split()) n l = sorted(l, reverse=True, key=lambda x: x[1]) sorted(l, reverse=True, key=lambda x: x[1]) l
n, m = map(int, input().split())
a = [int(i) for i in input().split()]
a = sorted(a)

l = []
for i in range(m):
  l.append(list(map(int, input().split())))
  
l = sorted(l, reverse=True, key=lambda x: x[1])

b = []
for _ in range(n):
  b.append(l[0][1])
  l[0][0] -= 1
  if l[0][0] == 0:
    l.pop(0)
  if l == []:
    break

for i in range(len(b)):
  if a[i] < b[i]:
    a[i] = b[i]
  else:
    break
    
print(sum(a))
