n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [ list(map(int, input().split())) for _ in range(m)]


# 最小値から順にCjより小さければ書き換えればよい　
# 毎回ソートしていたら間に合わなさそう
# Cを大きい順にソートして、カードの最小値をpop, キューの最後にCを加える
from collections import deque
import numpy as np
npbc = np.array(bc)
npbc = npbc[np.argsort(npbc[:, 1])[::-1]]
bc = npbc.tolist()
# print(bc)

que = deque(sorted(a))
for b, c in bc:
    for i in range(b):
        val = que.popleft()
        if val < c:
            que.append(c)
        else:
            que.appendleft(val)
            if i == 0:
                # print(que)
                print(sum(que))
                exit()
            else:
                break

# print(que)
print(sum(que)) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bc = [ list(map(int, input().split())) for _ in range(m)] bc [ list(map(int, input().split())) for _ in range(m)] from collections import deque import numpy as np numpy npbc = np.array(bc) npbc np.array(bc) np.array np array bc npbc = npbc[np.argsort(npbc[:, 1])[::-1]] npbc npbc[np.argsort(npbc[:, 1])[::-1]] npbc np.argsort(npbc[:, 1])[::-1] np.argsort(npbc[:, 1]) np.argsort np argsort npbc[:, 1] npbc : ::-1 -1 bc = npbc.tolist() bc npbc.tolist() npbc.tolist npbc tolist que = deque(sorted(a)) que deque(sorted(a)) deque sorted(a) sorted a for b, c in bc:
    for i in range(b):
        val = que.popleft()
        if val < c:
            que.append(c)
        else:
            que.appendleft(val)
            if i == 0:
                # print(que)
                print(sum(que))
                exit()
            else:
                break

# print(que) b c bc for i in range(b):
        val = que.popleft()
        if val < c:
            que.append(c)
        else:
            que.appendleft(val)
            if i == 0:
                # print(que)
                print(sum(que))
                exit()
            else:
                break

# print(que) i range(b) range b val = que.popleft() val que.popleft() que.popleft que popleft if val < c:
            que.append(c)
        else:
            que.appendleft(val)
            if i == 0:
                # print(que)
                print(sum(que))
                exit()
            else:
                break

# print(que) val < c val c que.append(c) que.append que append c que.appendleft(val) que.appendleft que appendleft val if i == 0:
                # print(que)
                print(sum(que))
                exit()
            else:
                break

# print(que) i == 0 i 0 print(sum(que)) print sum(que) sum que exit() exit break print(sum(que)) print sum(que) sum que m = map(int, input().split()) map(int, input().split()) m npbc = npbc[np.argsort(npbc[:, 1])[::-1]] npbc[np.argsort(npbc[:, 1])[::-1]] npbc a = list(map(int, input().split())) list(map(int, input().split())) a bc = [ list(map(int, input().split())) for _ in range(m)] [ list(map(int, input().split())) for _ in range(m)] bc n, m = map(int, input().split()) map(int, input().split()) n bc = npbc.tolist() npbc.tolist() bc que = deque(sorted(a)) deque(sorted(a)) que val = que.popleft() que.popleft() val npbc = np.array(bc) np.array(bc) npbc
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [ list(map(int, input().split())) for _ in range(m)]


# 最小値から順にCjより小さければ書き換えればよい　
# 毎回ソートしていたら間に合わなさそう
# Cを大きい順にソートして、カードの最小値をpop, キューの最後にCを加える
from collections import deque
import numpy as np
npbc = np.array(bc)
npbc = npbc[np.argsort(npbc[:, 1])[::-1]]
bc = npbc.tolist()
# print(bc)

que = deque(sorted(a))
for b, c in bc:
    for i in range(b):
        val = que.popleft()
        if val < c:
            que.append(c)
        else:
            que.appendleft(val)
            if i == 0:
                # print(que)
                print(sum(que))
                exit()
            else:
                break

# print(que)
print(sum(que))