import bisect
n,m =list(map(int,input().split()))
a = list(map(int,input().split()))
b = []
for i in range(m):
    c,d = list(map(int,input().split()))
    b.append([d,c])
a.sort()
a.reverse()
b.sort()
b.reverse()
c = []
i = 0
while True:
    if len(c)==n or i == m:
        break
    if b[i][1] >0:
        b[i][1] -=1
        c.append(b[i][0])
    else:
        i += 1
a+=c
a.sort()
a.reverse()
print(sum(a[0:n]))
# print(a)
 import bisect bisect n,m =list(map(int,input().split())) n list(map(int,input().split())) list 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 = [] b [] for i in range(m):
    c,d = list(map(int,input().split()))
    b.append([d,c]) i range(m) range m c,d = list(map(int,input().split())) c list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split d b.append([d,c]) b.append b append [d,c] d c a.sort() a.sort a sort a.reverse() a.reverse a reverse b.sort() b.sort b sort b.reverse() b.reverse b reverse c = [] c [] i = 0 i 0 while True:
    if len(c)==n or i == m:
        break
    if b[i][1] >0:
        b[i][1] -=1
        c.append(b[i][0])
    else:
        i += 1 True if len(c)==n or i == m:
        break
     len(c)==n or i == m len(c)==n len(c) len c n i == m i m break if b[i][1] >0:
        b[i][1] -=1
        c.append(b[i][0])
    else:
        i += 1 b[i][1] >0 b[i][1] [i] b i 1 0 b[i][1] -=1 b[i][1] [i] b i 1 1 c.append(b[i][0]) c.append c append b[i][0] [i] b i 0 i += 1 i 1 a+=c a c a.sort() a.sort a sort a.reverse() a.reverse a reverse print(sum(a[0:n])) print sum(a[0:n]) sum a[0:n] a 0:n 0 n i += 1 1 i d = list(map(int,input().split())) list(map(int,input().split())) d a = list(map(int,input().split())) list(map(int,input().split())) a c = [] [] c b = [] [] b i = 0 0 i a+=c c a m =list(map(int,input().split())) list(map(int,input().split())) m c,d = list(map(int,input().split())) list(map(int,input().split())) c n,m =list(map(int,input().split())) list(map(int,input().split())) n
import bisect
n,m =list(map(int,input().split()))
a = list(map(int,input().split()))
b = []
for i in range(m):
    c,d = list(map(int,input().split()))
    b.append([d,c])
a.sort()
a.reverse()
b.sort()
b.reverse()
c = []
i = 0
while True:
    if len(c)==n or i == m:
        break
    if b[i][1] >0:
        b[i][1] -=1
        c.append(b[i][0])
    else:
        i += 1
a+=c
a.sort()
a.reverse()
print(sum(a[0:n]))
# print(a)

