import heapq

import sys

input = sys.stdin.buffer.readline

from operator import itemgetter



def readlines(n):

    for _ in range(n):

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

        yield b, c



def main():

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

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

    total = sum(A)

    heapq.heapify(A)



    for b, c in sorted(readlines(M), key=itemgetter(1), reverse=True):

        for _ in range(b):

            o = heapq.heappushpop(A, c)

            if o < c:

                total += c - o

            else:

                break

            

    print(total)



main()
import heapq

import sys

input = sys.stdin.readline

from operator import itemgetter



def readlines(n):

    for _ in range(n):

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

        yield b, c



def main():

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

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



    change = []

    for b, c in sorted(readlines(M), key=itemgetter(1), reverse=True):

        change += [c] * b

        if len(change) > N:

            break



    A += change

    A.sort()

    answer = sum(A[-N:])

    print(answer)



main()
import heapq
import sys

input = sys.stdin.buffer.readline
from operator import itemgetter


def readlines(n):
    for _ in range(n):
        b, c = list(map(int, input().split()))
        yield b, c


def main():
    _, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    total = sum(A)
    heapq.heapify(A)
    for b, c in sorted(readlines(M), key=itemgetter(1), reverse=True):
        for _ in range(b):
            o = heapq.heappushpop(A, c)
            if o < c:
                total += c - o
            else:
                break
    print(total)


main()

import heapq
import sys

input = sys.stdin.readline
from operator import itemgetter


def readlines(n):
    for _ in range(n):
        b, c = list(map(int, input().split()))
        yield b, c


def main():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    change = []
    for b, c in sorted(readlines(M), key=itemgetter(1), reverse=True):
        change += [c] * b
        if len(change) > N:
            break
    A += change
    A.sort()
    answer = sum(A[-N:])
    print(answer)


main()

-input = sys.stdin.buffer.readline +input = sys.stdin.readline -    _, M = list(map(int, input().split())) +    N, M = list(map(int, input().split())) -    total = sum(A) -    heapq.heapify(A) +    change = [] -        for _ in range(b): -            o = heapq.heappushpop(A, c) -            if o < c: -                total += c - o -            else: -                break -    print(total) +        change += [c] * b +        if len(change) > N: +            break +    A += change +    A.sort() +    answer = sum(A[-N:]) +    print(answer)