import sys

stdin = sys.stdin



sys.setrecursionlimit(10 ** 7)



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

def li_(): return [int(x) - 1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())



from collections import defaultdict



dic = defaultdict(int)



n, m = li()

a = list(li())

key = set()





for ai in a:

    dic[ai] += 1

    key.add(ai)



for _ in range(m):

    bi, ci = li()

    dic[ci] += bi

    key.add(ci)



res = n

ans = 0

for ki in sorted(list(key), reverse=True):

    if res - dic[ki] >= 0:

        ans += ki*dic[ki]

        res -= dic[ki]

    else:

        ans += ki*res

        res = 0



    if res == 0:

        break

print(ans)

import sys

stdin = sys.stdin



sys.setrecursionlimit(10 ** 7)



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

def li_(): return [int(x) - 1 for x in stdin.readline().split()]

def lf(): return list(map(float, stdin.readline().split()))

def ls(): return stdin.readline().split()

def ns(): return stdin.readline().rstrip()

def lc(): return list(ns())

def ni(): return int(stdin.readline())

def nf(): return float(stdin.readline())



from collections import defaultdict



n, m = li()

a = list(li())



dic = defaultdict(int)



for ai in a:

    dic[ai] += 1



for _ in range(m):

    b, c = li()

    dic[c] += b



keys = sorted(list(dic.keys()), reverse=True)



rest = n

ans = 0

for ki in keys:

    if dic[ki] > rest:

        ans += ki * rest

        rest = 0



    elif dic[ki] == rest:

        ans += ki * dic[ki]

        rest = 0



    else:

        ans += ki * dic[ki]

        rest -= dic[ki]



    if rest <= 0:

        break



print(ans)

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)


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


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return list(map(float, stdin.readline().split()))


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(stdin.readline())


def nf():
    return float(stdin.readline())


from collections import defaultdict

dic = defaultdict(int)
n, m = li()
a = list(li())
key = set()
for ai in a:
    dic[ai] += 1
    key.add(ai)
for _ in range(m):
    bi, ci = li()
    dic[ci] += bi
    key.add(ci)
res = n
ans = 0
for ki in sorted(list(key), reverse=True):
    if res - dic[ki] >= 0:
        ans += ki * dic[ki]
        res -= dic[ki]
    else:
        ans += ki * res
        res = 0
    if res == 0:
        break
print(ans)

import sys

stdin = sys.stdin
sys.setrecursionlimit(10**7)


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


def li_():
    return [int(x) - 1 for x in stdin.readline().split()]


def lf():
    return list(map(float, stdin.readline().split()))


def ls():
    return stdin.readline().split()


def ns():
    return stdin.readline().rstrip()


def lc():
    return list(ns())


def ni():
    return int(stdin.readline())


def nf():
    return float(stdin.readline())


from collections import defaultdict

n, m = li()
a = list(li())
dic = defaultdict(int)
for ai in a:
    dic[ai] += 1
for _ in range(m):
    b, c = li()
    dic[c] += b
keys = sorted(list(dic.keys()), reverse=True)
rest = n
ans = 0
for ki in keys:
    if dic[ki] > rest:
        ans += ki * rest
        rest = 0
    elif dic[ki] == rest:
        ans += ki * dic[ki]
        rest = 0
    else:
        ans += ki * dic[ki]
        rest -= dic[ki]
    if rest <= 0:
        break
print(ans)

-dic = defaultdict(int) -key = set() +dic = defaultdict(int) -    key.add(ai) -    bi, ci = li() -    dic[ci] += bi -    key.add(ci) -res = n +    b, c = li() +    dic[c] += b +keys = sorted(list(dic.keys()), reverse=True) +rest = n -for ki in sorted(list(key), reverse=True): -    if res - dic[ki] >= 0: +for ki in keys: +    if dic[ki] > rest: +        ans += ki * rest +        rest = 0 +    elif dic[ki] == rest: -        res -= dic[ki] +        rest = 0 -        ans += ki * res -        res = 0 -    if res == 0: +        ans += ki * dic[ki] +        rest -= dic[ki] +    if rest <= 0: