import heapq

from sys import exit

N, M = list(map(int, input().split()))

A = list(map(int, input().split()))

BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)

heapq.heapify(A)



ans = sum(A)

for b, c in BC:

    for _ in range(b):

        if len(A) == 0:

            print(ans)

            exit()

        a = heapq.heappop(A)

        if a < c:

            ans += c - a

        else:

            print(ans)

            exit()

print(ans)

def main():

    import sys

    input = sys.stdin.readline

    N, M = list(map(int, input().split()))

    A = sorted(list(map(int, input().split())))

    BC = sorted([tuple(map(int, input().split())) for _ in range(M)], key=lambda x: x[1], reverse=True)

    ind = 0

    for b, c in BC:

        for i in range(b):

            if ind == N or A[ind] >= c:

                break

            A[ind] = c

            ind += 1

    print((sum(A)))





if __name__ == '__main__':

    main()
import heapq
from sys import exit

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = sorted(
    [tuple(map(int, input().split())) for _ in range(M)],
    key=lambda x: x[1],
    reverse=True,
)
heapq.heapify(A)
ans = sum(A)
for b, c in BC:
    for _ in range(b):
        if len(A) == 0:
            print(ans)
            exit()
        a = heapq.heappop(A)
        if a < c:
            ans += c - a
        else:
            print(ans)
            exit()
print(ans)

def main():
    import sys

    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    A = sorted(list(map(int, input().split())))
    BC = sorted(
        [tuple(map(int, input().split())) for _ in range(M)],
        key=lambda x: x[1],
        reverse=True,
    )
    ind = 0
    for b, c in BC:
        for i in range(b):
            if ind == N or A[ind] >= c:
                break
            A[ind] = c
            ind += 1
    print((sum(A)))


if __name__ == "__main__":
    main()

-import heapq -from sys import exit +def main(): +    import sys -N, M = list(map(int, input().split())) -A = list(map(int, input().split())) -BC = sorted( -    [tuple(map(int, input().split())) for _ in range(M)], -    key=lambda x: x[1], -    reverse=True, -) -heapq.heapify(A) -ans = sum(A) -for b, c in BC: -    for _ in range(b): -        if len(A) == 0: -            print(ans) -            exit() -        a = heapq.heappop(A) -        if a < c: -            ans += c - a -        else: -            print(ans) -            exit() -print(ans) +    input = sys.stdin.readline +    N, M = list(map(int, input().split())) +    A = sorted(list(map(int, input().split()))) +    BC = sorted( +        [tuple(map(int, input().split())) for _ in range(M)], +        key=lambda x: x[1], +        reverse=True, +    ) +    ind = 0 +    for b, c in BC: +        for i in range(b): +            if ind == N or A[ind] >= c: +                break +            A[ind] = c +            ind += 1 +    print((sum(A))) + + +if __name__ == "__main__": +    main()