import sys

from operator import itemgetter



n, m = list(map(int, input().split()))

a = list(map(int, sys.stdin.readline().split()))

bc = [ tuple(map(int, x.split())) for x in sys.stdin.readlines()]

bc.sort(key = itemgetter(1), reverse=True)

bc.append((n,0))

diff = []

for b, c in bc:

    diff += [c] * b

    if len(diff) > n:

        break



a += diff

a.sort()

print((sum(a[-n:])))

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

from operator import itemgetter



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

a = list(map(int, readline().split()))

m = list(map(int, read().split()))

bc = list(zip(m,m))



bc.sort(key = itemgetter(1), reverse=True)

bc.append((n,0))

diff = []

for b, c in bc:

    diff += [c] * b

    if len(diff) > n:

        break



a += diff

a.sort()

print((sum(a[-n:])))

import sys
from operator import itemgetter

n, m = list(map(int, input().split()))
a = list(map(int, sys.stdin.readline().split()))
bc = [tuple(map(int, x.split())) for x in sys.stdin.readlines()]
bc.sort(key=itemgetter(1), reverse=True)
bc.append((n, 0))
diff = []
for b, c in bc:
    diff += [c] * b
    if len(diff) > n:
        break
a += diff
a.sort()
print((sum(a[-n:])))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from operator import itemgetter

n, m = list(map(int, readline().split()))
a = list(map(int, readline().split()))
m = list(map(int, read().split()))
bc = list(zip(m, m))
bc.sort(key=itemgetter(1), reverse=True)
bc.append((n, 0))
diff = []
for b, c in bc:
    diff += [c] * b
    if len(diff) > n:
        break
a += diff
a.sort()
print((sum(a[-n:])))

+ +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline -n, m = list(map(int, input().split())) -a = list(map(int, sys.stdin.readline().split())) -bc = [tuple(map(int, x.split())) for x in sys.stdin.readlines()] +n, m = list(map(int, readline().split())) +a = list(map(int, readline().split())) +m = list(map(int, read().split())) +bc = list(zip(m, m))