from collections import Counter
n_cards, n_change = map(int,input().split())
a_ls = list(map(int, input().split()))
c = Counter(a_ls)
for i in range(n_change):
    time, card = map(int,input().split())
    c[card] += time

d = sorted(c.items(),key=lambda x:x[0], reverse=True)
ans = 0
rest = n_cards
for v, times in d:
    if times <= rest:
        ans += v*times
        rest -= times
    else:
        ans += v*rest
        break
print(ans) from collections import Counter n_cards, n_change = map(int,input().split()) n_cards map(int,input().split()) map int input().split() ().split () input split n_change a_ls = list(map(int, input().split())) a_ls list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split c = Counter(a_ls) c Counter(a_ls) Counter a_ls for i in range(n_change):
    time, card = map(int,input().split())
    c[card] += time i range(n_change) range n_change time, card = map(int,input().split()) time map(int,input().split()) map int input().split() ().split () input split card c[card] += time c[card] c card time d = sorted(c.items(),key=lambda x:x[0], reverse=True) d sorted(c.items(),key=lambda x:x[0], reverse=True) sorted c.items() c.items c items key=lambda x:x[0] key lambda x:x[0] x[0] x 0 x reverse=True reverse True ans = 0 ans 0 rest = n_cards rest n_cards for v, times in d:
    if times <= rest:
        ans += v*times
        rest -= times
    else:
        ans += v*rest
        break v times d if times <= rest:
        ans += v*times
        rest -= times
    else:
        ans += v*rest
        break times <= rest times rest ans += v*times ans v*times v times rest -= times rest times ans += v*rest ans v*rest v rest break print(ans) print ans time, card = map(int,input().split()) map(int,input().split()) time n_change = map(int,input().split()) map(int,input().split()) n_change ans = 0 0 ans n_cards, n_change = map(int,input().split()) map(int,input().split()) n_cards ans += v*rest v*rest ans d = sorted(c.items(),key=lambda x:x[0], reverse=True) sorted(c.items(),key=lambda x:x[0], reverse=True) d rest -= times times rest c = Counter(a_ls) Counter(a_ls) c a_ls = list(map(int, input().split())) list(map(int, input().split())) a_ls rest = n_cards n_cards rest card = map(int,input().split()) map(int,input().split()) card ans += v*times v*times ans
from collections import Counter
n_cards, n_change = map(int,input().split())
a_ls = list(map(int, input().split()))
c = Counter(a_ls)
for i in range(n_change):
    time, card = map(int,input().split())
    c[card] += time

d = sorted(c.items(),key=lambda x:x[0], reverse=True)
ans = 0
rest = n_cards
for v, times in d:
    if times <= rest:
        ans += v*times
        rest -= times
    else:
        ans += v*rest
        break
print(ans)