# ABC127D - Integer Cards

import sys



input = sys.stdin.readline





def main():

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

    num = sorted(list(map(int, input().rstrip().split())))

    lst = sorted(

        [tuple(map(int, input().rstrip().split())) for _ in range(m)],

        key=lambda x: x[1],

        reverse=True,

    )

    ans, idx = 0, 0

    flg = False

    for i, j in lst:

        for _ in range(i):

            if idx < n and num[idx] < j:

                ans += j

                idx += 1

            else:

                flg = True

                break

        if flg:

            break

    if idx < n:

        ans += sum(num[idx:])

    print(ans)





if __name__ == "__main__":

    main()
# ABC127D - Integer Cards

from operator import itemgetter as gt





def main():

    N, M, *X = list(map(int, open(0).read().split()))

    A, B = X[:N], [i for i in zip(*[iter(X[N:])] * 2)]

    A.sort(), B.sort(key=gt(1), reverse=1)

    ans, flg, idx = 0, 0, 0

    for i, j in B:

        for _ in range(i):

            if idx < N and A[idx] < j:

                ans += j

                idx += 1

            else:

                flg = 1

                break

        if flg:

            break

    if idx < N:

        ans += sum(A[idx:])

    print(ans)





if __name__ == "__main__":

    main()
# ABC127D - Integer Cards
import sys

input = sys.stdin.readline


def main():
    n, m = list(map(int, input().rstrip().split()))
    num = sorted(list(map(int, input().rstrip().split())))
    lst = sorted(
        [tuple(map(int, input().rstrip().split())) for _ in range(m)],
        key=lambda x: x[1],
        reverse=True,
    )
    ans, idx = 0, 0
    flg = False
    for i, j in lst:
        for _ in range(i):
            if idx < n and num[idx] < j:
                ans += j
                idx += 1
            else:
                flg = True
                break
        if flg:
            break
    if idx < n:
        ans += sum(num[idx:])
    print(ans)


if __name__ == "__main__":
    main()

# ABC127D - Integer Cards
from operator import itemgetter as gt


def main():
    N, M, *X = list(map(int, open(0).read().split()))
    A, B = X[:N], [i for i in zip(*[iter(X[N:])] * 2)]
    A.sort(), B.sort(key=gt(1), reverse=1)
    ans, flg, idx = 0, 0, 0
    for i, j in B:
        for _ in range(i):
            if idx < N and A[idx] < j:
                ans += j
                idx += 1
            else:
                flg = 1
                break
        if flg:
            break
    if idx < N:
        ans += sum(A[idx:])
    print(ans)


if __name__ == "__main__":
    main()

-import sys - -input = sys.stdin.readline +from operator import itemgetter as gt -    n, m = list(map(int, input().rstrip().split())) -    num = sorted(list(map(int, input().rstrip().split()))) -    lst = sorted( -        [tuple(map(int, input().rstrip().split())) for _ in range(m)], -        key=lambda x: x[1], -        reverse=True, -    ) -    ans, idx = 0, 0 -    flg = False -    for i, j in lst: +    N, M, *X = list(map(int, open(0).read().split())) +    A, B = X[:N], [i for i in zip(*[iter(X[N:])] * 2)] +    A.sort(), B.sort(key=gt(1), reverse=1) +    ans, flg, idx = 0, 0, 0 +    for i, j in B: -            if idx < n and num[idx] < j: +            if idx < N and A[idx] < j: -                flg = True +                flg = 1 -    if idx < n: -        ans += sum(num[idx:]) +    if idx < N: +        ans += sum(A[idx:])