def d_integer_cards(N, M, A, Operation_info):

    from bisect import bisect_left

    from collections import deque



    a = deque(sorted(A))

    Operation_info.sort(key=lambda x: x[1], reverse=True)



    tmp = []

    for b, c in Operation_info:

        index = bisect_left(a, c)

        if index > 0:

            for j in range(min(b, index)):

                a.popleft()

                tmp.append(c)

    return sum(list(a) + tmp)



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

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

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

print((d_integer_cards(N, M, A, Operation_info)))
def d_integer_cards(N, M, A, Operation_info):

    # Aの要素は1回選ぶことができるとみなす

    # 値C_iはB_i回選ぶことができるとみなす

    selected_num = [[1, a] for a in A] + Operation_info

    selected_num.sort(key=lambda x: x[1], reverse=True)



    # 値yをx回選ぶことを、選んだ値の個数がNになるまで繰り返す

    select = 0

    ans = 0

    for x, y in selected_num:

        select += x

        ans += x * y

        if select >= N:

            ans -= (select - N) * y

            break

    return ans



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

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

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

print((d_integer_cards(N, M, A, Operation_info)))
def d_integer_cards(N, M, A, Operation_info):
    from bisect import bisect_left
    from collections import deque

    a = deque(sorted(A))
    Operation_info.sort(key=lambda x: x[1], reverse=True)
    tmp = []
    for b, c in Operation_info:
        index = bisect_left(a, c)
        if index > 0:
            for j in range(min(b, index)):
                a.popleft()
                tmp.append(c)
    return sum(list(a) + tmp)


N, M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
Operation_info = [[int(i) for i in input().split()] for j in range(M)]
print((d_integer_cards(N, M, A, Operation_info)))

def d_integer_cards(N, M, A, Operation_info):
    # Aの要素は1回選ぶことができるとみなす
    # 値C_iはB_i回選ぶことができるとみなす
    selected_num = [[1, a] for a in A] + Operation_info
    selected_num.sort(key=lambda x: x[1], reverse=True)
    # 値yをx回選ぶことを、選んだ値の個数がNになるまで繰り返す
    select = 0
    ans = 0
    for x, y in selected_num:
        select += x
        ans += x * y
        if select >= N:
            ans -= (select - N) * y
            break
    return ans


N, M = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
Operation_info = [[int(i) for i in input().split()] for j in range(M)]
print((d_integer_cards(N, M, A, Operation_info)))

-    from bisect import bisect_left -    from collections import deque - -    a = deque(sorted(A)) -    Operation_info.sort(key=lambda x: x[1], reverse=True) -    tmp = [] -    for b, c in Operation_info: -        index = bisect_left(a, c) -        if index > 0: -            for j in range(min(b, index)): -                a.popleft() -                tmp.append(c) -    return sum(list(a) + tmp) +    # Aの要素は1回選ぶことができるとみなす +    # 値C_iはB_i回選ぶことができるとみなす +    selected_num = [[1, a] for a in A] + Operation_info +    selected_num.sort(key=lambda x: x[1], reverse=True) +    # 値yをx回選ぶことを、選んだ値の個数がNになるまで繰り返す +    select = 0 +    ans = 0 +    for x, y in selected_num: +        select += x +        ans += x * y +        if select >= N: +            ans -= (select - N) * y +            break +    return ans