import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())

import heapq
q = []
a = map(int, readline().split())
for i in a:
    heapq.heappush(q, (-i, 1))
for i in range(m):
    b, c = map(int, readline().split())
    heapq.heappush(q, (-c, b))

ans = 0
for i in range(n):
    p = heapq.heappop(q)
    ans += abs(p[0])
    if p[1] > 1:
        heapq.heappush(q, (p[0], p[1] - 1))

print(ans) import sys sys import itertools itertools import time time import math math sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 from collections import defaultdict read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines n, m = map(int, readline().split()) n map(int, readline().split()) map int readline().split() ().split () readline split m import heapq heapq q = [] q [] a = map(int, readline().split()) a map(int, readline().split()) map int readline().split() ().split () readline split for i in a:
    heapq.heappush(q, (-i, 1)) i a heapq.heappush(q, (-i, 1)) heapq.heappush heapq heappush q (-i, 1) -i i 1 for i in range(m):
    b, c = map(int, readline().split())
    heapq.heappush(q, (-c, b)) i range(m) range m b, c = map(int, readline().split()) b map(int, readline().split()) map int readline().split() ().split () readline split c heapq.heappush(q, (-c, b)) heapq.heappush heapq heappush q (-c, b) -c c b ans = 0 ans 0 for i in range(n):
    p = heapq.heappop(q)
    ans += abs(p[0])
    if p[1] > 1:
        heapq.heappush(q, (p[0], p[1] - 1)) i range(n) range n p = heapq.heappop(q) p heapq.heappop(q) heapq.heappop heapq heappop q ans += abs(p[0]) ans abs(p[0]) abs p[0] p 0 if p[1] > 1:
        heapq.heappush(q, (p[0], p[1] - 1)) p[1] > 1 p[1] p 1 1 heapq.heappush(q, (p[0], p[1] - 1)) heapq.heappush heapq heappush q (p[0], p[1] - 1) p[0] p 0 p[1] - 1 p[1] p 1 1 print(ans) print ans read = sys.stdin.buffer.read sys.stdin.buffer.read read m = map(int, readline().split()) map(int, readline().split()) m b, c = map(int, readline().split()) map(int, readline().split()) b a = map(int, readline().split()) map(int, readline().split()) a c = map(int, readline().split()) map(int, readline().split()) c ans += abs(p[0]) abs(p[0]) ans readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines n, m = map(int, readline().split()) map(int, readline().split()) n ans = 0 0 ans p = heapq.heappop(q) heapq.heappop(q) p readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline q = [] [] q
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())

import heapq
q = []
a = map(int, readline().split())
for i in a:
    heapq.heappush(q, (-i, 1))
for i in range(m):
    b, c = map(int, readline().split())
    heapq.heappush(q, (-c, b))

ans = 0
for i in range(n):
    p = heapq.heappop(q)
    ans += abs(p[0])
    if p[1] > 1:
        heapq.heappush(q, (p[0], p[1] - 1))

print(ans)