def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]

def input():

    return sys.stdin.readline().rstrip()



from collections import defaultdict, deque, Counter

from sys import exit

import heapq

import math

import copy

from operator import mul

from functools import reduce

from bisect import bisect_left, bisect_right



import sys

sys.setrecursionlimit(1000000000)



N, M = getNM()

A = getList()

A.sort()



lista = []

for i in range(M):

    b, c = getNM()

    lista.append([b, c])

lista.sort(reverse = True,key = lambda i:i[1])



listalta = [0]

for i in range(M):

    listalta.append(listalta[i] + lista[i][0])

listalta.pop(0)



for i in range(N):

    index = bisect_left(listalta, i + 1)

    # index >= M(indexが枠外に飛んでないか)

    if index != M and A[i] < lista[index][1]:

        A[i] = lista[index][1]

print((sum(A)))
def getN():

    return int(eval(input()))

def getNM():

    return list(map(int, input().split()))

def getList():

    return list(map(int, input().split()))

def getArray(intn):

    return [int(eval(input())) for i in range(intn)]

def input():

    return sys.stdin.readline().rstrip()

def rand_N(ran1, ran2):

    return random.randint(ran1, ran2)

def rand_List(ran1, ran2, rantime):

    return [random.randint(ran1, ran2) for i in range(rantime)]

def rand_ints_nodup(ran1, ran2, rantime):

  ns = []

  while len(ns) < rantime:

    n = random.randint(ran1, ran2)

    if not n in ns:

      ns.append(n)

  return sorted(ns)



def rand_query(ran1, ran2, rantime):

  r_query = []

  while len(r_query) < rantime:

    n_q = rand_ints_nodup(ran1, ran2, 2)

    if not n_q in r_query:

      r_query.append(n_q)

  return sorted(r_query)



from collections import defaultdict, deque, Counter

from sys import exit

from decimal import *

import heapq

from math import sqrt

from fractions import gcd

import random

import string

import copy

from itertools import combinations, permutations, product

from operator import mul, itemgetter

from functools import reduce

from bisect import bisect_left, bisect_right



import sys

sys.setrecursionlimit(1000000000)

mod = 10 ** 9 + 7



#############

# Main Code #

#############



N, M = getNM()

A = getList()

que = [getList() for i in range(M)]



A.sort()

que.sort(key = lambda i:i[1])

time, alt = que.pop()



ans = 0

for i in range(N):

    # もし操作用カードがなくなったら

    if time == 0 and len(que) > 0:

        time, alt = que.pop()



    if A[i] < alt and time > 0:

        time -= 1

        ans += alt

    else:

        ans += A[i]

print(ans)
def getN():
    return int(eval(input()))


def getNM():
    return list(map(int, input().split()))


def getList():
    return list(map(int, input().split()))


def getArray(intn):
    return [int(eval(input())) for i in range(intn)]


def input():
    return sys.stdin.readline().rstrip()


from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys

sys.setrecursionlimit(1000000000)
N, M = getNM()
A = getList()
A.sort()
lista = []
for i in range(M):
    b, c = getNM()
    lista.append([b, c])
lista.sort(reverse=True, key=lambda i: i[1])
listalta = [0]
for i in range(M):
    listalta.append(listalta[i] + lista[i][0])
listalta.pop(0)
for i in range(N):
    index = bisect_left(listalta, i + 1)
    # index >= M(indexが枠外に飛んでないか)
    if index != M and A[i] < lista[index][1]:
        A[i] = lista[index][1]
print((sum(A)))

def getN():
    return int(eval(input()))


def getNM():
    return list(map(int, input().split()))


def getList():
    return list(map(int, input().split()))


def getArray(intn):
    return [int(eval(input())) for i in range(intn)]


def input():
    return sys.stdin.readline().rstrip()


def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)


def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]


def rand_ints_nodup(ran1, ran2, rantime):
    ns = []
    while len(ns) < rantime:
        n = random.randint(ran1, ran2)
        if not n in ns:
            ns.append(n)
    return sorted(ns)


def rand_query(ran1, ran2, rantime):
    r_query = []
    while len(r_query) < rantime:
        n_q = rand_ints_nodup(ran1, ran2, 2)
        if not n_q in r_query:
            r_query.append(n_q)
    return sorted(r_query)


from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right
import sys

sys.setrecursionlimit(1000000000)
mod = 10**9 + 7
#############
# Main Code #
#############
N, M = getNM()
A = getList()
que = [getList() for i in range(M)]
A.sort()
que.sort(key=lambda i: i[1])
time, alt = que.pop()
ans = 0
for i in range(N):
    # もし操作用カードがなくなったら
    if time == 0 and len(que) > 0:
        time, alt = que.pop()
    if A[i] < alt and time > 0:
        time -= 1
        ans += alt
    else:
        ans += A[i]
print(ans)

+def rand_N(ran1, ran2): +    return random.randint(ran1, ran2) + + +def rand_List(ran1, ran2, rantime): +    return [random.randint(ran1, ran2) for i in range(rantime)] + + +def rand_ints_nodup(ran1, ran2, rantime): +    ns = [] +    while len(ns) < rantime: +        n = random.randint(ran1, ran2) +        if not n in ns: +            ns.append(n) +    return sorted(ns) + + +def rand_query(ran1, ran2, rantime): +    r_query = [] +    while len(r_query) < rantime: +        n_q = rand_ints_nodup(ran1, ran2, 2) +        if not n_q in r_query: +            r_query.append(n_q) +    return sorted(r_query) + + +from decimal import * -import math +from math import sqrt +from fractions import gcd +import random +import string -from operator import mul +from itertools import combinations, permutations, product +from operator import mul, itemgetter +mod = 10**9 + 7 +############# +# Main Code # +############# +que = [getList() for i in range(M)] -lista = [] -for i in range(M): -    b, c = getNM() -    lista.append([b, c]) -lista.sort(reverse=True, key=lambda i: i[1]) -listalta = [0] -for i in range(M): -    listalta.append(listalta[i] + lista[i][0]) -listalta.pop(0) +que.sort(key=lambda i: i[1]) +time, alt = que.pop() +ans = 0 -    index = bisect_left(listalta, i + 1) -    # index >= M(indexが枠外に飛んでないか) -    if index != M and A[i] < lista[index][1]: -        A[i] = lista[index][1] -print((sum(A))) +    # もし操作用カードがなくなったら +    if time == 0 and len(que) > 0: +        time, alt = que.pop() +    if A[i] < alt and time > 0: +        time -= 1 +        ans += alt +    else: +        ans += A[i] +print(ans)