from collections import Counter,defaultdict,deque

from heapq import heapify,heappop,heappush

from bisect import bisect_left,bisect_right

import sys,math,itertools,string,queue

sys.setrecursionlimit(10**8)

mod = 10**9+7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))



n,m = inpl()

a = inpl()

b = [0] * m

for i in range(m):

    x,y = inpl()

    b[i] = [x,y]

a.sort()

b.sort(key=lambda x:x[1], reverse = True)

res = sum(a)

i = 0

j = 0

while True:

    # print(i,j)

    if a[i] < b[j][1]:

        res += b[j][1] - a[i]

        i += 1

    else:

        break

    b[j][0] -= 1

    if b[j][0] == 0:

        j += 1

    if i >= n or j >= m:

        break

print(res)

from collections import Counter,defaultdict,deque

from heapq import heappop,heappush,heapify

from bisect import bisect_left,bisect_right 

import sys,math,itertools,fractions,pprint

sys.setrecursionlimit(10**8)

mod = 10**9+7

INF = float('inf')

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))



n,m = inpl()

a = inpl()

a.sort()

bc = [inpl() for _ in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

lm = sum(x[1] for x in bc)

now = 0

alt = 0

while now < n and alt < m:

    c,b = bc[alt]

    if a[now] > b:

        break

    else:

        a[now] = b

    bc[alt][0] -= 1

    if bc[alt][0] == 0:

        alt += 1

    now += 1

print((sum(a)))

from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, string, queue

sys.setrecursionlimit(10**8)
mod = 10**9 + 7


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


def inpl_str():
    return list(sys.stdin.readline().split())


def inpln(n):
    return list(int(sys.stdin.readline()) for i in range(n))


n, m = inpl()
a = inpl()
b = [0] * m
for i in range(m):
    x, y = inpl()
    b[i] = [x, y]
a.sort()
b.sort(key=lambda x: x[1], reverse=True)
res = sum(a)
i = 0
j = 0
while True:
    # print(i,j)
    if a[i] < b[j][1]:
        res += b[j][1] - a[i]
        i += 1
    else:
        break
    b[j][0] -= 1
    if b[j][0] == 0:
        j += 1
    if i >= n or j >= m:
        break
print(res)

from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint

sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


n, m = inpl()
a = inpl()
a.sort()
bc = [inpl() for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True)
lm = sum(x[1] for x in bc)
now = 0
alt = 0
while now < n and alt < m:
    c, b = bc[alt]
    if a[now] > b:
        break
    else:
        a[now] = b
    bc[alt][0] -= 1
    if bc[alt][0] == 0:
        alt += 1
    now += 1
print((sum(a)))

-from heapq import heapify, heappop, heappush +from heapq import heappop, heappush, heapify -import sys, math, itertools, string, queue +import sys, math, itertools, fractions, pprint +INF = float("inf") -def inpl_str(): -    return list(sys.stdin.readline().split()) - - -def inpln(n): -    return list(int(sys.stdin.readline()) for i in range(n)) - - -b = [0] * m -for i in range(m): -    x, y = inpl() -    b[i] = [x, y] -b.sort(key=lambda x: x[1], reverse=True) -res = sum(a) -i = 0 -j = 0 -while True: -    # print(i,j) -    if a[i] < b[j][1]: -        res += b[j][1] - a[i] -        i += 1 +bc = [inpl() for _ in range(m)] +bc.sort(key=lambda x: x[1], reverse=True) +lm = sum(x[1] for x in bc) +now = 0 +alt = 0 +while now < n and alt < m: +    c, b = bc[alt] +    if a[now] > b: +        break -        break -    b[j][0] -= 1 -    if b[j][0] == 0: -        j += 1 -    if i >= n or j >= m: -        break -print(res) +        a[now] = b +    bc[alt][0] -= 1 +    if bc[alt][0] == 0: +        alt += 1 +    now += 1 +print((sum(a)))