import heapq

from collections import Counter

from itertools import starmap

from operator import mul



R = lambda: list(map(int, input().split()))

n, m = R()

a = list(Counter(R()).items())

heapq.heapify(a)

for _ in range(m):

    b, c = R()

    i = b

    while i:

        x, y = a[0]

        if x >= c:

            break

        d = min(i, y)

        i -= d

        y -= d

        if y:

            heapq.heapreplace(a, (x, y))

        else:

            heapq.heappop(a)

    heapq.heappush(a, (c, b - i))

print((sum(starmap(mul, a))))

import heapq

from itertools import repeat, starmap

from operator import mul



R = lambda: list(map(int, input().split()))

n, m = R()

a = list(zip(R(), repeat(1)))

heapq.heapify(a)

for _ in range(m):

    b, c = R()

    i = b

    while i:

        x, y = a[0]

        if x >= c:

            break

        d = min(i, y)

        i -= d

        y -= d

        if y:

            heapq.heapreplace(a, (x, y))

        else:

            heapq.heappop(a)

    heapq.heappush(a, (c, b - i))

print((sum(starmap(mul, a))))

import heapq
from collections import Counter
from itertools import starmap
from operator import mul

R = lambda: list(map(int, input().split()))
n, m = R()
a = list(Counter(R()).items())
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i:
        x, y = a[0]
        if x >= c:
            break
        d = min(i, y)
        i -= d
        y -= d
        if y:
            heapq.heapreplace(a, (x, y))
        else:
            heapq.heappop(a)
    heapq.heappush(a, (c, b - i))
print((sum(starmap(mul, a))))

import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: list(map(int, input().split()))
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i:
        x, y = a[0]
        if x >= c:
            break
        d = min(i, y)
        i -= d
        y -= d
        if y:
            heapq.heapreplace(a, (x, y))
        else:
            heapq.heappop(a)
    heapq.heappush(a, (c, b - i))
print((sum(starmap(mul, a))))

-from collections import Counter -from itertools import starmap +from itertools import repeat, starmap -a = list(Counter(R()).items()) +a = list(zip(R(), repeat(1)))