import sys

from operator import itemgetter



def read():

    return sys.stdin.readline().rstrip()



def main():

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

    a = sorted(int(i) for i in read().split())

    bc = sorted([[int(i) for i in read().split()] for _ in range(m)], key=itemgetter(1), reverse=True)

    d = []

    for b, c in bc:

        if len(d) < n:

            d += [c] * b

    for i in range(min(n, len(d))):

        if a[i] < d[i]:

            a[i] = d[i]

        else:

            break

    print((sum(a)))



if __name__ == '__main__':

    main()
def main():

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

    a = sorted(int(i) for i in input().split())

    bc = [(0, 0) for _ in range(m)]

    for i in range(m):

        b, c = list(map(int, input().split()))

        bc[i] = (c, b)

    bc.sort(reverse=True)

    k = 0

    d = []

    for c, b in bc:

        if k + b > n:

            d += [c] * (n - k)

            break

        d += [c] * b

        k += b

    for i in range(len(d)):

        if a[i] < d[i]:

            a[i] = d[i]

        else:

            break

    print((sum(a)))





if __name__ == '__main__':

    main()

import sys
from operator import itemgetter


def read():
    return sys.stdin.readline().rstrip()


def main():
    n, m = list(map(int, read().split()))
    a = sorted(int(i) for i in read().split())
    bc = sorted(
        [[int(i) for i in read().split()] for _ in range(m)],
        key=itemgetter(1),
        reverse=True,
    )
    d = []
    for b, c in bc:
        if len(d) < n:
            d += [c] * b
    for i in range(min(n, len(d))):
        if a[i] < d[i]:
            a[i] = d[i]
        else:
            break
    print((sum(a)))


if __name__ == "__main__":
    main()

def main():
    n, m = list(map(int, input().split()))
    a = sorted(int(i) for i in input().split())
    bc = [(0, 0) for _ in range(m)]
    for i in range(m):
        b, c = list(map(int, input().split()))
        bc[i] = (c, b)
    bc.sort(reverse=True)
    k = 0
    d = []
    for c, b in bc:
        if k + b > n:
            d += [c] * (n - k)
            break
        d += [c] * b
        k += b
    for i in range(len(d)):
        if a[i] < d[i]:
            a[i] = d[i]
        else:
            break
    print((sum(a)))


if __name__ == "__main__":
    main()

-import sys -from operator import itemgetter - - -def read(): -    return sys.stdin.readline().rstrip() - - -    n, m = list(map(int, read().split())) -    a = sorted(int(i) for i in read().split()) -    bc = sorted( -        [[int(i) for i in read().split()] for _ in range(m)], -        key=itemgetter(1), -        reverse=True, -    ) +    n, m = list(map(int, input().split())) +    a = sorted(int(i) for i in input().split()) +    bc = [(0, 0) for _ in range(m)] +    for i in range(m): +        b, c = list(map(int, input().split())) +        bc[i] = (c, b) +    bc.sort(reverse=True) +    k = 0 -    for b, c in bc: -        if len(d) < n: -            d += [c] * b -    for i in range(min(n, len(d))): +    for c, b in bc: +        if k + b > n: +            d += [c] * (n - k) +            break +        d += [c] * b +        k += b +    for i in range(len(d)):