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

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

bc = [[int(i) for i in input().split()] for i in range(m)]

ans = 0

cnt = 0

d = {}



for i in range(n): 

    d[a[i]] = d.get(a[i],0)+1

for k in d: 

    bc.append([d[k],k])

bc.sort(key= lambda x:x[1],reverse=True)



for i in range(len(bc)):

    if cnt < n:

        ans += bc[i][1]*bc[i][0]

        cnt += bc[i][0]

    else:

        ans -= (cnt-n)*bc[i-1][1]

        break

else:

    ans -= (cnt-n)*bc[i][1]



print(ans)

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

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

bc = [[int(i) for i in input().split()] for i in range(m)]

a.sort()

bc.sort(key=lambda x:x[1],reverse=True)

d = []

cnt1 = 0

cnt2 = 0

x = 0



for lst in bc:

    cnt2 = 0

    while cnt1 < n and cnt2 < lst[0]:

        d.append(lst[1])

        cnt1 += 1

        cnt2 += 1



for i in range(len(d)):

    if d[i] - a[i] < 0:

        x = i

        break

else:

    x += i+1



print((sum(d[:x]+a[x:])))
n, m = list(map(int, input().split()))
a = [int(i) for i in input().split()]
bc = [[int(i) for i in input().split()] for i in range(m)]
ans = 0
cnt = 0
d = {}
for i in range(n):
    d[a[i]] = d.get(a[i], 0) + 1
for k in d:
    bc.append([d[k], k])
bc.sort(key=lambda x: x[1], reverse=True)
for i in range(len(bc)):
    if cnt < n:
        ans += bc[i][1] * bc[i][0]
        cnt += bc[i][0]
    else:
        ans -= (cnt - n) * bc[i - 1][1]
        break
else:
    ans -= (cnt - n) * bc[i][1]
print(ans)

n, m = list(map(int, input().split()))
a = [int(i) for i in input().split()]
bc = [[int(i) for i in input().split()] for i in range(m)]
a.sort()
bc.sort(key=lambda x: x[1], reverse=True)
d = []
cnt1 = 0
cnt2 = 0
x = 0
for lst in bc:
    cnt2 = 0
    while cnt1 < n and cnt2 < lst[0]:
        d.append(lst[1])
        cnt1 += 1
        cnt2 += 1
for i in range(len(d)):
    if d[i] - a[i] < 0:
        x = i
        break
else:
    x += i + 1
print((sum(d[:x] + a[x:])))

-ans = 0 -cnt = 0 -d = {} -for i in range(n): -    d[a[i]] = d.get(a[i], 0) + 1 -for k in d: -    bc.append([d[k], k]) +a.sort() -for i in range(len(bc)): -    if cnt < n: -        ans += bc[i][1] * bc[i][0] -        cnt += bc[i][0] -    else: -        ans -= (cnt - n) * bc[i - 1][1] +d = [] +cnt1 = 0 +cnt2 = 0 +x = 0 +for lst in bc: +    cnt2 = 0 +    while cnt1 < n and cnt2 < lst[0]: +        d.append(lst[1]) +        cnt1 += 1 +        cnt2 += 1 +for i in range(len(d)): +    if d[i] - a[i] < 0: +        x = i -    ans -= (cnt - n) * bc[i][1] -print(ans) +    x += i + 1 +print((sum(d[:x] + a[x:])))