from collections import defaultdict



if __name__ == "__main__":

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

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

    bc = [list(map(int, input().split())) for _ in range(m)]



    card = defaultdict(int)

    for aa in a:

        card[aa] += 1



    for c in bc:

        card[c[1]] += c[0]



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



    ans = 0

    res = n

    for c in card_sort:

        if c[1] >= res:

            ans += res * c[0]

            break

        else:

            ans += c[0] * c[1]

            res -= c[1]



    print(ans)

from collections import defaultdict



if __name__ == "__main__":

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

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

    bc = [list(map(int, input().split())) for _ in range(m)]



    card = defaultdict(int)

    for aa in a:

        card[aa] += 1



    for task in bc:

        card[task[1]] += task[0]



    key = sorted(list(card.keys()), reverse=True)



    res = n

    ans = 0

    for k in key:

        if card[k] >= res:

            ans += res * k

            break

        else:

            ans += card[k] * k

            res -= card[k]



    print(ans)

from collections import defaultdict

if __name__ == "__main__":
    n, m = list(map(int, input().split()))
    a = list(map(int, input().split()))
    bc = [list(map(int, input().split())) for _ in range(m)]
    card = defaultdict(int)
    for aa in a:
        card[aa] += 1
    for c in bc:
        card[c[1]] += c[0]
    card_sort = sorted(list(card.items()), key=lambda x: x[0], reverse=True)
    ans = 0
    res = n
    for c in card_sort:
        if c[1] >= res:
            ans += res * c[0]
            break
        else:
            ans += c[0] * c[1]
            res -= c[1]
    print(ans)

from collections import defaultdict

if __name__ == "__main__":
    n, m = list(map(int, input().split()))
    a = list(map(int, input().split()))
    bc = [list(map(int, input().split())) for _ in range(m)]
    card = defaultdict(int)
    for aa in a:
        card[aa] += 1
    for task in bc:
        card[task[1]] += task[0]
    key = sorted(list(card.keys()), reverse=True)
    res = n
    ans = 0
    for k in key:
        if card[k] >= res:
            ans += res * k
            break
        else:
            ans += card[k] * k
            res -= card[k]
    print(ans)

-    for c in bc: -        card[c[1]] += c[0] -    card_sort = sorted(list(card.items()), key=lambda x: x[0], reverse=True) +    for task in bc: +        card[task[1]] += task[0] +    key = sorted(list(card.keys()), reverse=True) +    res = n -    res = n -    for c in card_sort: -        if c[1] >= res: -            ans += res * c[0] +    for k in key: +        if card[k] >= res: +            ans += res * k -            ans += c[0] * c[1] -            res -= c[1] +            ans += card[k] * k +            res -= card[k]