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

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

arr=sorted(arr)

q=[list(map(int,input().split())) for _ in range(m)]

q=sorted(q,reverse=True,key=lambda x:x[0])

q=sorted(q,reverse=True,key=lambda x:x[1])

pos=0

for i in range(n):

  if arr[i]<=q[pos][1]:

    arr[i]=q[pos][1]

    q[pos][0]-=1

    if q[pos][0]==0:

      pos+=1

      if pos==m:

        break

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

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

arr=[list(map(int,input().split())) for _ in range(m)]

arr=sorted(arr,reverse=True,key=lambda x:x[1])

tmp=0

for cnt,val in arr:

  ans+=[val]*cnt

  tmp+=cnt

  if tmp>=n:

    break

ans=sorted(ans,reverse=True)

print((sum(ans[:n])))
n, m = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr = sorted(arr)
q = [list(map(int, input().split())) for _ in range(m)]
q = sorted(q, reverse=True, key=lambda x: x[0])
q = sorted(q, reverse=True, key=lambda x: x[1])
pos = 0
for i in range(n):
    if arr[i] <= q[pos][1]:
        arr[i] = q[pos][1]
        q[pos][0] -= 1
        if q[pos][0] == 0:
            pos += 1
            if pos == m:
                break
print((sum(arr)))

n, m = list(map(int, input().split()))
ans = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(m)]
arr = sorted(arr, reverse=True, key=lambda x: x[1])
tmp = 0
for cnt, val in arr:
    ans += [val] * cnt
    tmp += cnt
    if tmp >= n:
        break
ans = sorted(ans, reverse=True)
print((sum(ans[:n])))

-arr = list(map(int, input().split())) -arr = sorted(arr) -q = [list(map(int, input().split())) for _ in range(m)] -q = sorted(q, reverse=True, key=lambda x: x[0]) -q = sorted(q, reverse=True, key=lambda x: x[1]) -pos = 0 -for i in range(n): -    if arr[i] <= q[pos][1]: -        arr[i] = q[pos][1] -        q[pos][0] -= 1 -        if q[pos][0] == 0: -            pos += 1 -            if pos == m: -                break -print((sum(arr))) +ans = list(map(int, input().split())) +arr = [list(map(int, input().split())) for _ in range(m)] +arr = sorted(arr, reverse=True, key=lambda x: x[1]) +tmp = 0 +for cnt, val in arr: +    ans += [val] * cnt +    tmp += cnt +    if tmp >= n: +        break +ans = sorted(ans, reverse=True) +print((sum(ans[:n])))