# ABC127D - Integer Cards

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





def main():

    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, idx = 0, 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)





if __name__ == "__main__":

    main()
# ABC127D - Integer Cards
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


def main():
    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, idx = 0, 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)


if __name__ == "__main__":
    main()

-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 +import sys + +input = sys.stdin.readline + + +def main(): +    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, idx = 0, 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: -    if flg: -        break -if idx < n: -    ans += sum(num[idx:]) -print(ans) +    if idx < n: +        ans += sum(num[idx:]) +    print(ans) + + +if __name__ == "__main__": +    main()