import heapq

import sys

input = sys.stdin.readline



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=lambda x: -x[1]):

        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():

    _, 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


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=lambda x: -x[1]):
        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():
    _, 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()

+from operator import itemgetter -    for b, c in sorted(readlines(M), key=lambda x: -x[1]): +    for b, c in sorted(readlines(M), key=itemgetter(1), reverse=True):