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

bc = {}

a = list(input().split())

for i in a:

  if i in bc:

    bc[i] += 1

  else:

    bc[i] = 1

for i in range(m):

  b,c = input().split()

  b = int(b)

  if c in bc:

    bc[c] += b

  else:

    bc.update({c:b})

key = sorted(bc)

for k in range(len(key)):

  key[k] = int(key[k])

key.sort()

key.reverse()

for k in range(len(key)):

  key[k] = str(key[k])

c = 0

s = 0

for i in key:

  if i in bc:

    s += int(i) * bc[i]

    c += bc[i]

    if c > n:

      s -= int(i) * (c-n)

      c -= c-n

  if c == n:

    break

print(s)
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 = sorted(bc,key=lambda x:x[1])

bc.reverse()

count = 0

for b,c in bc:

  count += b

  a += [c] * b

  if count >= n:

    break

a.sort()

a.reverse()

print((sum(a[:n])))
n, m = list(map(int, input().split()))
bc = {}
a = list(input().split())
for i in a:
    if i in bc:
        bc[i] += 1
    else:
        bc[i] = 1
for i in range(m):
    b, c = input().split()
    b = int(b)
    if c in bc:
        bc[c] += b
    else:
        bc.update({c: b})
key = sorted(bc)
for k in range(len(key)):
    key[k] = int(key[k])
key.sort()
key.reverse()
for k in range(len(key)):
    key[k] = str(key[k])
c = 0
s = 0
for i in key:
    if i in bc:
        s += int(i) * bc[i]
        c += bc[i]
        if c > n:
            s -= int(i) * (c - n)
            c -= c - n
    if c == n:
        break
print(s)

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 = sorted(bc, key=lambda x: x[1])
bc.reverse()
count = 0
for b, c in bc:
    count += b
    a += [c] * b
    if count >= n:
        break
a.sort()
a.reverse()
print((sum(a[:n])))

-bc = {} -a = list(input().split()) -for i in a: -    if i in bc: -        bc[i] += 1 -    else: -        bc[i] = 1 +a = list(map(int, input().split())) +bc = [] -    b, c = input().split() -    b = int(b) -    if c in bc: -        bc[c] += b -    else: -        bc.update({c: b}) -key = sorted(bc) -for k in range(len(key)): -    key[k] = int(key[k]) -key.sort() -key.reverse() -for k in range(len(key)): -    key[k] = str(key[k]) -c = 0 -s = 0 -for i in key: -    if i in bc: -        s += int(i) * bc[i] -        c += bc[i] -        if c > n: -            s -= int(i) * (c - n) -            c -= c - n -    if c == n: +    b, c = list(map(int, input().split())) +    bc.append((b, c)) +bc = sorted(bc, key=lambda x: x[1]) +bc.reverse() +count = 0 +for b, c in bc: +    count += b +    a += [c] * b +    if count >= n: -print(s) +a.sort() +a.reverse() +print((sum(a[:n])))