def main():

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

    a = [int(x) for x in input().split()]

    cards = {}

    for aa in a:

        if aa in cards:

            cards[aa] += 1

        else:

            cards[aa] = 1

    for _ in range(m):

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

        if c in cards:

            cards[c] += b

        else:

            cards[c] = b

    cards = sorted(list(cards.items()), key=lambda x: x[0], reverse=True)

    answer = 0

    for val, count in cards:

        if n <= 0:

            break

        else:

            answer += min(n, count) * val

            n -= min(n, count)

    print(answer)





if __name__ == '__main__':

    main()



from collections import Counter





def main():

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

    a = Counter(list(map(int, input().split())))

    cards = []

    for i, v in list(a.items()):

        cards.append([i, v])

    for _ in range(m):

        cards.append(list(map(int, input().split()))[::-1])

    cards.sort(key=lambda x: x[0], reverse=True)

    ans = 0

    for i, v in cards:

        ans += i * min(v, n)

        n -= min(v, n)

    print(ans)





if __name__ == '__main__':

    main()



def main():
    n, m = list(map(int, input().split()))
    a = [int(x) for x in input().split()]
    cards = {}
    for aa in a:
        if aa in cards:
            cards[aa] += 1
        else:
            cards[aa] = 1
    for _ in range(m):
        b, c = list(map(int, input().split()))
        if c in cards:
            cards[c] += b
        else:
            cards[c] = b
    cards = sorted(list(cards.items()), key=lambda x: x[0], reverse=True)
    answer = 0
    for val, count in cards:
        if n <= 0:
            break
        else:
            answer += min(n, count) * val
            n -= min(n, count)
    print(answer)


if __name__ == "__main__":
    main()

from collections import Counter


def main():
    n, m = list(map(int, input().split()))
    a = Counter(list(map(int, input().split())))
    cards = []
    for i, v in list(a.items()):
        cards.append([i, v])
    for _ in range(m):
        cards.append(list(map(int, input().split()))[::-1])
    cards.sort(key=lambda x: x[0], reverse=True)
    ans = 0
    for i, v in cards:
        ans += i * min(v, n)
        n -= min(v, n)
    print(ans)


if __name__ == "__main__":
    main()

+from collections import Counter + + -    a = [int(x) for x in input().split()] -    cards = {} -    for aa in a: -        if aa in cards: -            cards[aa] += 1 -        else: -            cards[aa] = 1 +    a = Counter(list(map(int, input().split()))) +    cards = [] +    for i, v in list(a.items()): +        cards.append([i, v]) -        b, c = list(map(int, input().split())) -        if c in cards: -            cards[c] += b -        else: -            cards[c] = b -    cards = sorted(list(cards.items()), key=lambda x: x[0], reverse=True) -    answer = 0 -    for val, count in cards: -        if n <= 0: -            break -        else: -            answer += min(n, count) * val -            n -= min(n, count) -    print(answer) +        cards.append(list(map(int, input().split()))[::-1]) +    cards.sort(key=lambda x: x[0], reverse=True) +    ans = 0 +    for i, v in cards: +        ans += i * min(v, n) +        n -= min(v, n) +    print(ans)