# from pprint import pprint
# import math
import collections

# n = int(input())
n, m = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = [None] * m
c = [None] * m
for i in range(m):
    _b, _c = map(int, input().split(' '))
    b[i] = _b
    c[i] = _c

cnt = collections.Counter(a)

# カウンターのみ更新
for j in range(m):
    cnt.update({c[j]: b[j]})

a_tup = cnt.items()

# カウンターの結果を逆順にして合計n個になるまで取り出して加算
res = 0
num_cnt = 0
for _ in sorted(a_tup, reverse=True):
    res += _[0] * _[1]
    num_cnt += _[1]

    # n個を超えたらその分減らす
    if num_cnt >= n:
        res -= _[0] * (num_cnt - n)
        break

print(res) import collections collections n, m = map(int, input().split(' ')) n map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' m a = list(map(int, input().split(' '))) a list(map(int, input().split(' '))) list map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' b = [None] * m b [None] * m [None] None m c = [None] * m c [None] * m [None] None m for i in range(m):
    _b, _c = map(int, input().split(' '))
    b[i] = _b
    c[i] = _c i range(m) range m _b, _c = map(int, input().split(' ')) _b map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' _c b[i] = _b b[i] b i _b c[i] = _c c[i] c i _c cnt = collections.Counter(a) cnt collections.Counter(a) collections.Counter collections Counter a for j in range(m):
    cnt.update({c[j]: b[j]}) j range(m) range m cnt.update({c[j]: b[j]}) cnt.update cnt update {c[j]: b[j]} c[j] c[j] c j b[j] b j a_tup = cnt.items() a_tup cnt.items() cnt.items cnt items res = 0 res 0 num_cnt = 0 num_cnt 0 for _ in sorted(a_tup, reverse=True):
    res += _[0] * _[1]
    num_cnt += _[1]

    # n個を超えたらその分減らす
    if num_cnt >= n:
        res -= _[0] * (num_cnt - n)
        break _ sorted(a_tup, reverse=True) sorted a_tup reverse=True reverse True res += _[0] * _[1] res _[0] * _[1] _[0] _ 0 _[1] _ 1 num_cnt += _[1] num_cnt _[1] _ 1 if num_cnt >= n:
        res -= _[0] * (num_cnt - n)
        break num_cnt >= n num_cnt n res -= _[0] * (num_cnt - n) res _[0] * (num_cnt - n) _[0] _ 0 num_cnt - n num_cnt n break print(res) print res num_cnt += _[1] _[1] num_cnt _b, _c = map(int, input().split(' ')) map(int, input().split(' ')) _b cnt = collections.Counter(a) collections.Counter(a) cnt res -= _[0] * (num_cnt - n) _[0] * (num_cnt - n) res a_tup = cnt.items() cnt.items() a_tup n, m = map(int, input().split(' ')) map(int, input().split(' ')) n b = [None] * m [None] * m b res += _[0] * _[1] _[0] * _[1] res _c = map(int, input().split(' ')) map(int, input().split(' ')) _c a = list(map(int, input().split(' '))) list(map(int, input().split(' '))) a m = map(int, input().split(' ')) map(int, input().split(' ')) m c = [None] * m [None] * m c res = 0 0 res num_cnt = 0 0 num_cnt
# from pprint import pprint
# import math
import collections

# n = int(input())
n, m = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = [None] * m
c = [None] * m
for i in range(m):
    _b, _c = map(int, input().split(' '))
    b[i] = _b
    c[i] = _c

cnt = collections.Counter(a)

# カウンターのみ更新
for j in range(m):
    cnt.update({c[j]: b[j]})

a_tup = cnt.items()

# カウンターの結果を逆順にして合計n個になるまで取り出して加算
res = 0
num_cnt = 0
for _ in sorted(a_tup, reverse=True):
    res += _[0] * _[1]
    num_cnt += _[1]

    # n個を超えたらその分減らす
    if num_cnt >= n:
        res -= _[0] * (num_cnt - n)
        break

print(res)
