import sys

import heapq



input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)





def main():

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



    H = []

    for i in list(map(int, input().split())):

        heapq.heappush(H, [-i, 1])



    for i in range(M):

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

        heapq.heappush(H, [-c, b])



    cnt = 1

    ans = 0

    while cnt <= N:

        c, b = heapq.heappop(H)

        c = -c

        ans += c

        if b > 1:

            b -= 1

            heapq.heappush(H, [-c, b])

        cnt += 1



    print(ans)





if __name__ == "__main__":

    main()

import sys

import heapq



input = sys.stdin.readline

sys.setrecursionlimit(10 ** 7)





def main():

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



    H = []

    for i in list(map(int, input().split())):

        heapq.heappush(H, (-i, 1))



    for i in range(M):

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

        heapq.heappush(H, (-c, b))



    cnt = 1

    ans = 0

    while cnt <= N:

        c, b = heapq.heappop(H)

        c = -c

        ans += c

        if b > 1:

            b -= 1

            heapq.heappush(H, (-c, b))

        cnt += 1



    print(ans)





if __name__ == "__main__":

    main()

import sys
import heapq

input = sys.stdin.readline
sys.setrecursionlimit(10**7)


def main():
    N, M = list(map(int, input().split()))
    H = []
    for i in list(map(int, input().split())):
        heapq.heappush(H, [-i, 1])
    for i in range(M):
        b, c = list(map(int, input().split()))
        heapq.heappush(H, [-c, b])
    cnt = 1
    ans = 0
    while cnt <= N:
        c, b = heapq.heappop(H)
        c = -c
        ans += c
        if b > 1:
            b -= 1
            heapq.heappush(H, [-c, b])
        cnt += 1
    print(ans)


if __name__ == "__main__":
    main()

import sys
import heapq

input = sys.stdin.readline
sys.setrecursionlimit(10**7)


def main():
    N, M = list(map(int, input().split()))
    H = []
    for i in list(map(int, input().split())):
        heapq.heappush(H, (-i, 1))
    for i in range(M):
        b, c = list(map(int, input().split()))
        heapq.heappush(H, (-c, b))
    cnt = 1
    ans = 0
    while cnt <= N:
        c, b = heapq.heappop(H)
        c = -c
        ans += c
        if b > 1:
            b -= 1
            heapq.heappush(H, (-c, b))
        cnt += 1
    print(ans)


if __name__ == "__main__":
    main()

-        heapq.heappush(H, [-i, 1]) +        heapq.heappush(H, (-i, 1)) -        heapq.heappush(H, [-c, b]) +        heapq.heappush(H, (-c, b)) -            heapq.heappush(H, [-c, b]) +            heapq.heappush(H, (-c, b))