# ABC127D - Integer Cards

import sys

input = sys.stdin.readline



n, m = list(map(int, input().rstrip().split()))

num = sorted(list(map(int, input().rstrip().split())))

lst = sorted([list(map(int, input().rstrip().split())) for _ in range(m)], key=lambda x:x[1], reverse=True)

ans = 0

idx = 0

flg = False

for i, j in lst:

    for _ in range(i):

        if idx < n and num[idx] < j:

            ans += j

            idx += 1

        else:

            flg = True

            break

    if flg:

        break

if idx < n:

    ans += sum(num[idx:])

print(ans)
# ABC127D - Integer Cards

import sys

input = sys.stdin.readline



n, m = list(map(int, input().rstrip().split()))

num = sorted(list(map(int, input().rstrip().split())))

lst = sorted([tuple(map(int, input().rstrip().split())) for _ in range(m)], key=lambda x:x[1], reverse=True)

ans = 0

idx = 0

flg = False

for i, j in lst:

    for _ in range(i):

        if idx < n and num[idx] < j:

            ans += j

            idx += 1

        else:

            flg = True

            break

    if flg:

        break

if idx < n:

    ans += sum(num[idx:])

print(ans)
# ABC127D - Integer Cards
import sys

input = sys.stdin.readline
n, m = list(map(int, input().rstrip().split()))
num = sorted(list(map(int, input().rstrip().split())))
lst = sorted(
    [list(map(int, input().rstrip().split())) for _ in range(m)],
    key=lambda x: x[1],
    reverse=True,
)
ans = 0
idx = 0
flg = False
for i, j in lst:
    for _ in range(i):
        if idx < n and num[idx] < j:
            ans += j
            idx += 1
        else:
            flg = True
            break
    if flg:
        break
if idx < n:
    ans += sum(num[idx:])
print(ans)

# ABC127D - Integer Cards
import sys

input = sys.stdin.readline
n, m = list(map(int, input().rstrip().split()))
num = sorted(list(map(int, input().rstrip().split())))
lst = sorted(
    [tuple(map(int, input().rstrip().split())) for _ in range(m)],
    key=lambda x: x[1],
    reverse=True,
)
ans = 0
idx = 0
flg = False
for i, j in lst:
    for _ in range(i):
        if idx < n and num[idx] < j:
            ans += j
            idx += 1
        else:
            flg = True
            break
    if flg:
        break
if idx < n:
    ans += sum(num[idx:])
print(ans)

-    [list(map(int, input().rstrip().split())) for _ in range(m)], +    [tuple(map(int, input().rstrip().split())) for _ in range(m)],