import numpy as np



N, M = list(map(int,input().split()))



As = sorted(list(map(int,input().split())))

BCs = []



for i in range(M):

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

	BCs.append(inputs)

BCs = sorted(BCs, reverse = True, key=lambda x: x[1])



index = 0

for bc in BCs:

	b = bc[0]

	c = bc[1]



	for n in range(b):

		try:

			if As[index] < c:

				As[index] = c

				index += 1

			else:

				break

		except:

			break

print((sum(As)))

import numpy as np



def main():

	N, M = list(map(int,input().split()))



	As = sorted(list(map(int,input().split())))

	BCs = []



	for i in range(M):

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

		BCs.append(inputs)

	BCs = sorted(BCs, reverse = True, key=lambda x: x[1])



	index = 0

	for bc in BCs:

		b = bc[0]

		c = bc[1]



		for n in range(b):

			try:

				if As[index] < c:

					As[index] = c

					index += 1

				else:

					print((sum(As)))

					return

			except:

				print((sum(As)))

				return

	print((sum(As)))



if __name__ == '__main__':

	main()
import numpy as np

N, M = list(map(int, input().split()))
As = sorted(list(map(int, input().split())))
BCs = []
for i in range(M):
    inputs = list(map(int, input().split()))
    BCs.append(inputs)
BCs = sorted(BCs, reverse=True, key=lambda x: x[1])
index = 0
for bc in BCs:
    b = bc[0]
    c = bc[1]
    for n in range(b):
        try:
            if As[index] < c:
                As[index] = c
                index += 1
            else:
                break
        except:
            break
print((sum(As)))

import numpy as np


def main():
    N, M = list(map(int, input().split()))
    As = sorted(list(map(int, input().split())))
    BCs = []
    for i in range(M):
        inputs = list(map(int, input().split()))
        BCs.append(inputs)
    BCs = sorted(BCs, reverse=True, key=lambda x: x[1])
    index = 0
    for bc in BCs:
        b = bc[0]
        c = bc[1]
        for n in range(b):
            try:
                if As[index] < c:
                    As[index] = c
                    index += 1
                else:
                    print((sum(As)))
                    return
            except:
                print((sum(As)))
                return
    print((sum(As)))


if __name__ == "__main__":
    main()

-N, M = list(map(int, input().split())) -As = sorted(list(map(int, input().split()))) -BCs = [] -for i in range(M): -    inputs = list(map(int, input().split())) -    BCs.append(inputs) -BCs = sorted(BCs, reverse=True, key=lambda x: x[1]) -index = 0 -for bc in BCs: -    b = bc[0] -    c = bc[1] -    for n in range(b): -        try: -            if As[index] < c: -                As[index] = c -                index += 1 -            else: -                break -        except: -            break -print((sum(As))) + +def main(): +    N, M = list(map(int, input().split())) +    As = sorted(list(map(int, input().split()))) +    BCs = [] +    for i in range(M): +        inputs = list(map(int, input().split())) +        BCs.append(inputs) +    BCs = sorted(BCs, reverse=True, key=lambda x: x[1]) +    index = 0 +    for bc in BCs: +        b = bc[0] +        c = bc[1] +        for n in range(b): +            try: +                if As[index] < c: +                    As[index] = c +                    index += 1 +                else: +                    print((sum(As))) +                    return +            except: +                print((sum(As))) +                return +    print((sum(As))) + + +if __name__ == "__main__": +    main()