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

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

cb = [list(map(int,input().split()))[::-1] for _ in range(m) ]

cb.append([-1,1])



a.sort()

cb.sort()



i= n-1

j = m



ans = 0

remain = n

while(remain > 0):

    if( a[i] > cb[j][0] ):

        ans += a[i]

        i -= 1

        remain -= 1

    else:

        ans += cb[j][0] * min(remain, cb[j][1])

        remain -= cb[j][1]

        j -= 1



print(ans)
import sys

input = sys.stdin.readline



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

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

cb = [list(map(int,input().split()))[::-1] for _ in range(m) ]

cb.append([-1,1])



a.sort()

cb.sort()



i= n-1

j = m



ans = 0

remain = n

while(remain > 0):

    if( a[i] > cb[j][0] ):

        ans += a[i]

        i -= 1

        remain -= 1

    else:

        ans += cb[j][0] * min(remain, cb[j][1])

        remain -= cb[j][1]

        j -= 1



print(ans)

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cb = [list(map(int, input().split()))[::-1] for _ in range(m)]
cb.append([-1, 1])
a.sort()
cb.sort()
i = n - 1
j = m
ans = 0
remain = n
while remain > 0:
    if a[i] > cb[j][0]:
        ans += a[i]
        i -= 1
        remain -= 1
    else:
        ans += cb[j][0] * min(remain, cb[j][1])
        remain -= cb[j][1]
        j -= 1
print(ans)

import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cb = [list(map(int, input().split()))[::-1] for _ in range(m)]
cb.append([-1, 1])
a.sort()
cb.sort()
i = n - 1
j = m
ans = 0
remain = n
while remain > 0:
    if a[i] > cb[j][0]:
        ans += a[i]
        i -= 1
        remain -= 1
    else:
        ans += cb[j][0] * min(remain, cb[j][1])
        remain -= cb[j][1]
        j -= 1
print(ans)

+import sys + +input = sys.stdin.readline