import sys

from collections import defaultdict



input = sys.stdin.readline



def main():

    N, M = list(map(int, input().split()))

    A = list(map(int, input().split()))

    d = defaultdict(int)

    for _ in range(M):

        B, C = list(map(int, input().split()))

        d[C] += B

    

    for a in A:

        d[a] += 1



    sort_d = sorted(list(d.items()),reverse = True)

    

    cnt = 0

    ans = 0

    for i,j in sort_d:

        if cnt + j < N:

            ans += i * j

            cnt += j

        elif cnt + j >= N:

            if cnt == N:

                break

            ans += i * (N - cnt)

            break 



    print(ans)



main()
from collections import defaultdict



def main():

    N, M = list(map(int, input().split()))

    A = list(map(int, input().split()))

    d = defaultdict(int)

    for i in range(M):

        B, C = list(map(int, input().split()))

        d[C] += B

    

    for a in A:

        d[a] += 1



    ans = 0

    cnt = 0

    for i in sorted(list(d.keys()),reverse=True):

        if cnt + d[i] < N:

            ans += d[i] * i

            cnt += d[i]

        else:

            ans += i * (N - cnt)

            cnt = N

            break



    print(ans)







if __name__ == "__main__":

    main()
import sys
from collections import defaultdict

input = sys.stdin.readline


def main():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for _ in range(M):
        B, C = list(map(int, input().split()))
        d[C] += B
    for a in A:
        d[a] += 1
    sort_d = sorted(list(d.items()), reverse=True)
    cnt = 0
    ans = 0
    for i, j in sort_d:
        if cnt + j < N:
            ans += i * j
            cnt += j
        elif cnt + j >= N:
            if cnt == N:
                break
            ans += i * (N - cnt)
            break
    print(ans)


main()

from collections import defaultdict


def main():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for i in range(M):
        B, C = list(map(int, input().split()))
        d[C] += B
    for a in A:
        d[a] += 1
    ans = 0
    cnt = 0
    for i in sorted(list(d.keys()), reverse=True):
        if cnt + d[i] < N:
            ans += d[i] * i
            cnt += d[i]
        else:
            ans += i * (N - cnt)
            cnt = N
            break
    print(ans)


if __name__ == "__main__":
    main()

-import sys - -input = sys.stdin.readline -    for _ in range(M): +    for i in range(M): -    sort_d = sorted(list(d.items()), reverse=True) +    ans = 0 -    ans = 0 -    for i, j in sort_d: -        if cnt + j < N: -            ans += i * j -            cnt += j -        elif cnt + j >= N: -            if cnt == N: -                break +    for i in sorted(list(d.keys()), reverse=True): +        if cnt + d[i] < N: +            ans += d[i] * i +            cnt += d[i] +        else: +            cnt = N -main() +if __name__ == "__main__": +    main()