import sys, math, collections, heapq, itertools



F = sys.stdin

def single_input(): return F.readline().strip("\n")

def line_input(): return F.readline().strip("\n").split()

def gcd(a, b):

    a, b = max(a, b), min(a, b)

    while a % b > 0: a, b = b, a % b

    return b

  

def solve():

    N, M = list(map(int, line_input()))

    A = [int(a) for a in line_input()]

    change = [None] * M

    for i in range(M):

        b, c = list(map(int, line_input()))

        change[i] = [c, b]

    A.sort()

    change.sort(reverse = True)



    sum = 0

    index = 0

    for c, b in change:

        bleft = b

        while bleft > 0:

            if c > A[index]:

                sum += c

                index += 1

                bleft -= 1

                if index == N: break

            else: break

        if index == N: break

    if index < N:

        for i in range(index, N):

            sum += A[i]

    print(sum)



    return 0

  

if __name__ == "__main__":

    solve()
import sys

from operator import itemgetter



def solve():

    input = sys.stdin.readline

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

    A = [int(a) for a in input().split()]

    A.sort()

    C = [[int(i) for i in input().split()] for _ in range(M)]

    C.sort(key=itemgetter(1), reverse = True)

    counter = 0

    for b, c in C:

        end = False

        for j in range(b):

            if counter > N - 1: 

                end = True

                break

            if A[counter] < c:

                A[counter] = c

                counter += 1

            else:

                end = True

                break

        if end: break

    print((sum(A)))

        

    return 0



if __name__ == "__main__":

    solve()
import sys, math, collections, heapq, itertools

F = sys.stdin


def single_input():
    return F.readline().strip("\n")


def line_input():
    return F.readline().strip("\n").split()


def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b


def solve():
    N, M = list(map(int, line_input()))
    A = [int(a) for a in line_input()]
    change = [None] * M
    for i in range(M):
        b, c = list(map(int, line_input()))
        change[i] = [c, b]
    A.sort()
    change.sort(reverse=True)
    sum = 0
    index = 0
    for c, b in change:
        bleft = b
        while bleft > 0:
            if c > A[index]:
                sum += c
                index += 1
                bleft -= 1
                if index == N:
                    break
            else:
                break
        if index == N:
            break
    if index < N:
        for i in range(index, N):
            sum += A[i]
    print(sum)
    return 0


if __name__ == "__main__":
    solve()

import sys
from operator import itemgetter


def solve():
    input = sys.stdin.readline
    N, M = list(map(int, input().split()))
    A = [int(a) for a in input().split()]
    A.sort()
    C = [[int(i) for i in input().split()] for _ in range(M)]
    C.sort(key=itemgetter(1), reverse=True)
    counter = 0
    for b, c in C:
        end = False
        for j in range(b):
            if counter > N - 1:
                end = True
                break
            if A[counter] < c:
                A[counter] = c
                counter += 1
            else:
                end = True
                break
        if end:
            break
    print((sum(A)))
    return 0


if __name__ == "__main__":
    solve()

-import sys, math, collections, heapq, itertools - -F = sys.stdin - - -def single_input(): -    return F.readline().strip("\n") - - -def line_input(): -    return F.readline().strip("\n").split() - - -def gcd(a, b): -    a, b = max(a, b), min(a, b) -    while a % b > 0: -        a, b = b, a % b -    return b +import sys +from operator import itemgetter -    N, M = list(map(int, line_input())) -    A = [int(a) for a in line_input()] -    change = [None] * M -    for i in range(M): -        b, c = list(map(int, line_input())) -        change[i] = [c, b] +    input = sys.stdin.readline +    N, M = list(map(int, input().split())) +    A = [int(a) for a in input().split()] -    change.sort(reverse=True) -    sum = 0 -    index = 0 -    for c, b in change: -        bleft = b -        while bleft > 0: -            if c > A[index]: -                sum += c -                index += 1 -                bleft -= 1 -                if index == N: -                    break +    C = [[int(i) for i in input().split()] for _ in range(M)] +    C.sort(key=itemgetter(1), reverse=True) +    counter = 0 +    for b, c in C: +        end = False +        for j in range(b): +            if counter > N - 1: +                end = True +                break +            if A[counter] < c: +                A[counter] = c +                counter += 1 +                end = True -        if index == N: +        if end: -    if index < N: -        for i in range(index, N): -            sum += A[i] -    print(sum) +    print((sum(A)))