import heapq
from collections import defaultdict
n, m =map(int, input().split())
a=list(map(int, input().split()))

for i in range(n):
  a[i] *= -1


pri=list(set(a))
heapq.heapify(pri)
dict=defaultdict(int)
for i in a:
  dict[-i] += 1
for i in range(m):
  b, c = map(int, input().split())
  dict[c] += b
  heapq.heappush(pri,-c)
# print (pri)
# print (dict)

ans = 0
cnt = 0
old = 0
while True:
  x = heapq.heappop(pri)
  x *= -1
  if old == x:
    continue
  if cnt+dict[x] > n:
    ans += (n-cnt)*x
    cnt += n-cnt
  else:
    ans += dict[x]*x
    cnt += dict[x]
  if cnt >= n:
    break
  old = x
print (ans) import heapq heapq from collections import defaultdict 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 for i in range(n):
  a[i] *= -1 i range(n) range n a[i] *= -1 a[i] a i -1 pri=list(set(a)) pri list(set(a)) list set(a) set a heapq.heapify(pri) heapq.heapify heapq heapify pri dict=defaultdict(int) dict defaultdict(int) defaultdict int for i in a:
  dict[-i] += 1 i a dict[-i] += 1 dict[-i] dict -i i 1 for i in range(m):
  b, c = map(int, input().split())
  dict[c] += b
  heapq.heappush(pri,-c)
# print (pri)
# print (dict) i range(m) range m b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c dict[c] += b dict[c] dict c b heapq.heappush(pri,-c) heapq.heappush heapq heappush pri -c c ans = 0 ans 0 cnt = 0 cnt 0 old = 0 old 0 while True:
  x = heapq.heappop(pri)
  x *= -1
  if old == x:
    continue
  if cnt+dict[x] > n:
    ans += (n-cnt)*x
    cnt += n-cnt
  else:
    ans += dict[x]*x
    cnt += dict[x]
  if cnt >= n:
    break
  old = x True x = heapq.heappop(pri) x heapq.heappop(pri) heapq.heappop heapq heappop pri x *= -1 x -1 if old == x:
    continue
   old == x old x continue if cnt+dict[x] > n:
    ans += (n-cnt)*x
    cnt += n-cnt
  else:
    ans += dict[x]*x
    cnt += dict[x]
   cnt+dict[x] > n cnt+dict[x] cnt dict[x] dict x n ans += (n-cnt)*x ans (n-cnt)*x n-cnt n cnt x cnt += n-cnt cnt n-cnt n cnt ans += dict[x]*x ans dict[x]*x dict[x] dict x x cnt += dict[x] cnt dict[x] dict x if cnt >= n:
    break
   cnt >= n cnt n break old = x old x print (ans) print ans b, c = map(int, input().split()) map(int, input().split()) b a=list(map(int, input().split())) list(map(int, input().split())) a old = 0 0 old cnt += n-cnt n-cnt cnt cnt += dict[x] dict[x] cnt old = x x old n, m =map(int, input().split()) map(int, input().split()) n dict=defaultdict(int) defaultdict(int) dict x = heapq.heappop(pri) heapq.heappop(pri) x ans = 0 0 ans pri=list(set(a)) list(set(a)) pri ans += dict[x]*x dict[x]*x ans c = map(int, input().split()) map(int, input().split()) c cnt = 0 0 cnt x *= -1 -1 x ans += (n-cnt)*x (n-cnt)*x ans m =map(int, input().split()) map(int, input().split()) m
import heapq
from collections import defaultdict
n, m =map(int, input().split())
a=list(map(int, input().split()))

for i in range(n):
  a[i] *= -1


pri=list(set(a))
heapq.heapify(pri)
dict=defaultdict(int)
for i in a:
  dict[-i] += 1
for i in range(m):
  b, c = map(int, input().split())
  dict[c] += b
  heapq.heappush(pri,-c)
# print (pri)
# print (dict)

ans = 0
cnt = 0
old = 0
while True:
  x = heapq.heappop(pri)
  x *= -1
  if old == x:
    continue
  if cnt+dict[x] > n:
    ans += (n-cnt)*x
    cnt += n-cnt
  else:
    ans += dict[x]*x
    cnt += dict[x]
  if cnt >= n:
    break
  old = x
print (ans)
