def main():

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

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

    h = {}

    for i in range(m):

        b,c = list(map(int,input().split()))

        if c not in list(h.keys()):

            h[c] = b

        else:

            h[c]+=b

    for i in range(n):

        if a[i] not in list(h.keys()):

            h[a[i]]=1

        else:

            h[a[i]]+=1

    ans = 0

    for k in sorted(list(h.keys()),reverse=True):

        if n<h[k]:

            ans += n*k

            break

        ans += h[k]*k

        n = n-h[k]

    print(ans)





if __name__ == "__main__":

    main()

def main():

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

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

    dic = {}

    for i in range(n):

        if a[i] not in list(dic.keys()):

            dic[a[i]] = 1

        else:

            dic[a[i]] += 1

    for i in range(m):

        b,c = list(map(int,input().split()))

        if c not in list(dic.keys()):

            dic[c] = b

        else:

            dic[c] += b

    cnt = 0

    ans = 0

    for k in sorted(list(dic.keys()),reverse=True):

        if cnt + dic[k] < n:

            ans += dic[k]*k

            cnt = cnt + dic[k]

        else:

            ans += k *(n-cnt)

            print(ans)

            return



if __name__ == "__main__":

    main()

def main():
    n, m = list(map(int, input().split()))
    a = list(map(int, input().split()))
    h = {}
    for i in range(m):
        b, c = list(map(int, input().split()))
        if c not in list(h.keys()):
            h[c] = b
        else:
            h[c] += b
    for i in range(n):
        if a[i] not in list(h.keys()):
            h[a[i]] = 1
        else:
            h[a[i]] += 1
    ans = 0
    for k in sorted(list(h.keys()), reverse=True):
        if n < h[k]:
            ans += n * k
            break
        ans += h[k] * k
        n = n - h[k]
    print(ans)


if __name__ == "__main__":
    main()

def main():
    n, m = list(map(int, input().split()))
    a = list(map(int, input().split()))
    dic = {}
    for i in range(n):
        if a[i] not in list(dic.keys()):
            dic[a[i]] = 1
        else:
            dic[a[i]] += 1
    for i in range(m):
        b, c = list(map(int, input().split()))
        if c not in list(dic.keys()):
            dic[c] = b
        else:
            dic[c] += b
    cnt = 0
    ans = 0
    for k in sorted(list(dic.keys()), reverse=True):
        if cnt + dic[k] < n:
            ans += dic[k] * k
            cnt = cnt + dic[k]
        else:
            ans += k * (n - cnt)
            print(ans)
            return


if __name__ == "__main__":
    main()

-    h = {} +    dic = {} +    for i in range(n): +        if a[i] not in list(dic.keys()): +            dic[a[i]] = 1 +        else: +            dic[a[i]] += 1 -        if c not in list(h.keys()): -            h[c] = b +        if c not in list(dic.keys()): +            dic[c] = b -            h[c] += b -    for i in range(n): -        if a[i] not in list(h.keys()): -            h[a[i]] = 1 +            dic[c] += b +    cnt = 0 +    ans = 0 +    for k in sorted(list(dic.keys()), reverse=True): +        if cnt + dic[k] < n: +            ans += dic[k] * k +            cnt = cnt + dic[k] -            h[a[i]] += 1 -    ans = 0 -    for k in sorted(list(h.keys()), reverse=True): -        if n < h[k]: -            ans += n * k -            break -        ans += h[k] * k -        n = n - h[k] -    print(ans) +            ans += k * (n - cnt) +            print(ans) +            return