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 and a[0][0] < c:

        x, y = a[0]

        if y > i:

            a[0] = x, y - i

            i = 0

        else:

            heapq.heappop(a)

            i -= y

    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 and a[0][0] < c:

        x, y = a[0]

        if i < y:

            a[0] = x, y - i

            i = 0

        else:

            heapq.heappop(a)

            i -= y

    if i < b:

        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 and a[0][0] < c:
        x, y = a[0]
        if y > i:
            a[0] = x, y - i
            i = 0
        else:
            heapq.heappop(a)
            i -= y
    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 and a[0][0] < c:
        x, y = a[0]
        if i < y:
            a[0] = x, y - i
            i = 0
        else:
            heapq.heappop(a)
            i -= y
    if i < b:
        heapq.heappush(a, (c, b - i))
print((sum(starmap(mul, a))))

-        if y > i: +        if i < y: -    heapq.heappush(a, (c, b - i)) +    if i < b: +        heapq.heappush(a, (c, b - i))