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

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



bc =[]

for i in range(m):

    b,c = list(map(int,input().split()))

    bc.append((b,c))



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

newcard=[]

for b,c in bc:

    newcard.extend([c]*b)

    if(len(newcard)>=n):

        break



size = min(n,len(newcard))

a.sort()

for i in range(size):

    if(newcard[i]>a[i]):

        a[i]=newcard[i]

    else:

        break

print((sum(a)))
import sys

input = sys.stdin.readline

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

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



bc =[]

for i in range(m):

    b,c = list(map(int,input().split()))

    bc.append((b,c))



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

newcard=[]

for b,c in bc:

    newcard.extend([c]*b)

    if(len(newcard)>=n):

        break

a += newcard

a.sort(reverse=True)

print((sum(a[:n])))
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = []
for i in range(m):
    b, c = list(map(int, input().split()))
    bc.append((b, c))
bc.sort(key=lambda x: x[1], reverse=True)
newcard = []
for b, c in bc:
    newcard.extend([c] * b)
    if len(newcard) >= n:
        break
size = min(n, len(newcard))
a.sort()
for i in range(size):
    if newcard[i] > a[i]:
        a[i] = newcard[i]
    else:
        break
print((sum(a)))

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = []
for i in range(m):
    b, c = list(map(int, input().split()))
    bc.append((b, c))
bc.sort(key=lambda x: x[1], reverse=True)
newcard = []
for b, c in bc:
    newcard.extend([c] * b)
    if len(newcard) >= n:
        break
a += newcard
a.sort(reverse=True)
print((sum(a[:n])))

+import sys + +input = sys.stdin.readline -size = min(n, len(newcard)) -a.sort() -for i in range(size): -    if newcard[i] > a[i]: -        a[i] = newcard[i] -    else: -        break -print((sum(a))) +a += newcard +a.sort(reverse=True) +print((sum(a[:n])))