def main():

    import sys

    input = sys.stdin.buffer.readline

    from heapq import heappush, heappop, heapify

    N, M = (int(i) for i in input().split())

    A = [int(i) for i in input().split()]

    BC = [[int(i) for i in input().split()] for j in range(M)]

    heapify(A)

    BC.sort(key=lambda p: p[1], reverse=True)

    j = 0

    while j < M:

        a = heappop(A)

        c = BC[j][1]

        if c <= a:

            heappush(A, a)

            break

        else:

            heappush(A, c)

            BC[j][0] -= 1

            if BC[j][0] == 0:

                j += 1

    # print(A)

    print((sum(A)))





if __name__ == '__main__':

    main()

def main():

    from heapq import heapify, heappushpop

    _, M = (int(i) for i in input().split())

    A = ([int(i) for i in input().split()])

    BC = [[int(i) for i in input().split()] for j in range(M)]



    heapify(A)

    BC.sort(lambda p: p[1], reverse=True)

    for b, c in BC:

        if A[0] >= c:

            break

        for _ in range(b):

            if A[0] >= c:

                break

            heappushpop(A, c)

    print((sum(A)))





if __name__ == '__main__':

    main()

def main():
    import sys

    input = sys.stdin.buffer.readline
    from heapq import heappush, heappop, heapify

    N, M = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    BC = [[int(i) for i in input().split()] for j in range(M)]
    heapify(A)
    BC.sort(key=lambda p: p[1], reverse=True)
    j = 0
    while j < M:
        a = heappop(A)
        c = BC[j][1]
        if c <= a:
            heappush(A, a)
            break
        else:
            heappush(A, c)
            BC[j][0] -= 1
            if BC[j][0] == 0:
                j += 1
    # print(A)
    print((sum(A)))


if __name__ == "__main__":
    main()

def main():
    from heapq import heapify, heappushpop

    _, M = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    BC = [[int(i) for i in input().split()] for j in range(M)]
    heapify(A)
    BC.sort(lambda p: p[1], reverse=True)
    for b, c in BC:
        if A[0] >= c:
            break
        for _ in range(b):
            if A[0] >= c:
                break
            heappushpop(A, c)
    print((sum(A)))


if __name__ == "__main__":
    main()

-    import sys +    from heapq import heapify, heappushpop -    input = sys.stdin.buffer.readline -    from heapq import heappush, heappop, heapify - -    N, M = (int(i) for i in input().split()) +    _, M = (int(i) for i in input().split()) -    BC.sort(key=lambda p: p[1], reverse=True) -    j = 0 -    while j < M: -        a = heappop(A) -        c = BC[j][1] -        if c <= a: -            heappush(A, a) +    BC.sort(lambda p: p[1], reverse=True) +    for b, c in BC: +        if A[0] >= c: -        else: -            heappush(A, c) -            BC[j][0] -= 1 -            if BC[j][0] == 0: -                j += 1 -    # print(A) +        for _ in range(b): +            if A[0] >= c: +                break +            heappushpop(A, c)