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

ls = sorted(map(int, input().split()))

ls2 = [list(map(int, input().split())) for _ in range(m)]

ls2.sort(key=lambda x: (x[1], x[0]), reverse=True)

left = 0

right = 0

index = 0

res = 0

while left < n:

    if index == len(ls2):

        break

    b, c = ls2[index]

    if c <= ls[left]:

        break

    right = left + 1

    while right <= n:

        if right == n:

            res += c * (right - left)

            break

        if ls[right] <= c and right - left < b:

            right += 1

        else:

            res += c * (right - left)

            break

    left = right

    index += 1



print((res + sum(ls[left:])))
import operator

import sys



input = sys.stdin.readline



ri = lambda: int(eval(input()))

rs = lambda: input().rstrip()

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

rsl = lambda: input().rstrip().split()

ris = lambda n: [ri() for _ in range(n)]

rss = lambda n: [rs() for _ in range(n)]

rils = lambda n: [ril() for _ in range(n)]

rsls = lambda n: [rsl() for _ in range(n)]



n, m = ril()

ls = ril()

ls2 = rils(m)

ls.sort()

ls2.sort(key=operator.itemgetter(1), reverse=True)

res = 0

index = 0

b, c = ls2[0]

for x in ls:

    res += x

    if x < c:

        res += c - x

        b -= 1

        if b == 0:

            index += 1

            if index < m:

                b, c = ls2[index]

            else:

                c = -1

print(res)
n, m = list(map(int, input().split()))
ls = sorted(map(int, input().split()))
ls2 = [list(map(int, input().split())) for _ in range(m)]
ls2.sort(key=lambda x: (x[1], x[0]), reverse=True)
left = 0
right = 0
index = 0
res = 0
while left < n:
    if index == len(ls2):
        break
    b, c = ls2[index]
    if c <= ls[left]:
        break
    right = left + 1
    while right <= n:
        if right == n:
            res += c * (right - left)
            break
        if ls[right] <= c and right - left < b:
            right += 1
        else:
            res += c * (right - left)
            break
    left = right
    index += 1
print((res + sum(ls[left:])))

import operator
import sys

input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
n, m = ril()
ls = ril()
ls2 = rils(m)
ls.sort()
ls2.sort(key=operator.itemgetter(1), reverse=True)
res = 0
index = 0
b, c = ls2[0]
for x in ls:
    res += x
    if x < c:
        res += c - x
        b -= 1
        if b == 0:
            index += 1
            if index < m:
                b, c = ls2[index]
            else:
                c = -1
print(res)

-n, m = list(map(int, input().split())) -ls = sorted(map(int, input().split())) -ls2 = [list(map(int, input().split())) for _ in range(m)] -ls2.sort(key=lambda x: (x[1], x[0]), reverse=True) -left = 0 -right = 0 +import operator +import sys + +input = sys.stdin.readline +ri = lambda: int(eval(input())) +rs = lambda: input().rstrip() +ril = lambda: list(map(int, input().split())) +rsl = lambda: input().rstrip().split() +ris = lambda n: [ri() for _ in range(n)] +rss = lambda n: [rs() for _ in range(n)] +rils = lambda n: [ril() for _ in range(n)] +rsls = lambda n: [rsl() for _ in range(n)] +n, m = ril() +ls = ril() +ls2 = rils(m) +ls.sort() +ls2.sort(key=operator.itemgetter(1), reverse=True) +res = 0 -res = 0 -while left < n: -    if index == len(ls2): -        break -    b, c = ls2[index] -    if c <= ls[left]: -        break -    right = left + 1 -    while right <= n: -        if right == n: -            res += c * (right - left) -            break -        if ls[right] <= c and right - left < b: -            right += 1 -        else: -            res += c * (right - left) -            break -    left = right -    index += 1 -print((res + sum(ls[left:]))) +b, c = ls2[0] +for x in ls: +    res += x +    if x < c: +        res += c - x +        b -= 1 +        if b == 0: +            index += 1 +            if index < m: +                b, c = ls2[index] +            else: +                c = -1 +print(res)