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

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

b=[]

for i in range(m):

    bb,cc=list(map(int,input().split()))

    b.append([cc,bb])

a.sort()

b.sort(reverse=True)



i=0

j=0

while i<n:

    if j==m:

        break

    if b[j][1]>0:

        if a[i]<b[j][0]:

            a[i]=b[j][0]

            b[j][1]-=1

            i+=1

        elif a[i]>=b[j][0]:

            break

    else:

        j+=1

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

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

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

a.sort()

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

# print(a)

# print(bc)

i=0

for b,c in bc:

  tb=b

  while tb>0:

    if n==i:

      break

    if a[i]>=c:

      break

    a[i]=c

    tb-=1

    i+=1

  if n==i:break

  if a[i]>=c :

    break

print((sum(a)))
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = []
for i in range(m):
    bb, cc = list(map(int, input().split()))
    b.append([cc, bb])
a.sort()
b.sort(reverse=True)
i = 0
j = 0
while i < n:
    if j == m:
        break
    if b[j][1] > 0:
        if a[i] < b[j][0]:
            a[i] = b[j][0]
            b[j][1] -= 1
            i += 1
        elif a[i] >= b[j][0]:
            break
    else:
        j += 1
print((sum(a)))

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x: x[1], reverse=True)
# print(a)
# print(bc)
i = 0
for b, c in bc:
    tb = b
    while tb > 0:
        if n == i:
            break
        if a[i] >= c:
            break
        a[i] = c
        tb -= 1
        i += 1
    if n == i:
        break
    if a[i] >= c:
        break
print((sum(a)))

-b = [] -for i in range(m): -    bb, cc = list(map(int, input().split())) -    b.append([cc, bb]) +bc = [list(map(int, input().split())) for i in range(m)] -b.sort(reverse=True) +bc.sort(key=lambda x: x[1], reverse=True) +# print(a) +# print(bc) -j = 0 -while i < n: -    if j == m: +for b, c in bc: +    tb = b +    while tb > 0: +        if n == i: +            break +        if a[i] >= c: +            break +        a[i] = c +        tb -= 1 +        i += 1 +    if n == i: -    if b[j][1] > 0: -        if a[i] < b[j][0]: -            a[i] = b[j][0] -            b[j][1] -= 1 -            i += 1 -        elif a[i] >= b[j][0]: -            break -    else: -        j += 1 +    if a[i] >= c: +        break