import bisect

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

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

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

a.sort()

bc.sort(key=lambda x:x[1],reverse=True)

s=0

for i in range(m):

  if a[s]<bc[i][1]:

    t=bisect.bisect_left(a,bc[i][1],s,n)

    for j in range(s,min(t,s+bc[i][0])):

      a[j]=bc[i][1]

    s=min(t,s+bc[i][0])

    if s>=n:

      break

  else:

    break

print((sum(a)))

import bisect

import sys

input=sys.stdin.readline

from operator import itemgetter

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

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

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

a.sort()

bc.sort(key=itemgetter(1),reverse=True)

s=0

ans=0

for i in range(m):

  if a[s]<bc[i][1]:

    t=bisect.bisect_left(a,bc[i][1],s,n)

    cvt=min(t-s,bc[i][0])

    ans+=bc[i][1]*cvt

    s+=cvt

    if s>=n:

      break

  else:

    break

print((ans+sum(a[s:])))

import bisect

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(m)]
a.sort()
bc.sort(key=lambda x: x[1], reverse=True)
s = 0
for i in range(m):
    if a[s] < bc[i][1]:
        t = bisect.bisect_left(a, bc[i][1], s, n)
        for j in range(s, min(t, s + bc[i][0])):
            a[j] = bc[i][1]
        s = min(t, s + bc[i][0])
        if s >= n:
            break
    else:
        break
print((sum(a)))

import bisect
import sys

input = sys.stdin.readline
from operator import itemgetter

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
bc = [list(map(int, input().split())) for i in range(m)]
a.sort()
bc.sort(key=itemgetter(1), reverse=True)
s = 0
ans = 0
for i in range(m):
    if a[s] < bc[i][1]:
        t = bisect.bisect_left(a, bc[i][1], s, n)
        cvt = min(t - s, bc[i][0])
        ans += bc[i][1] * cvt
        s += cvt
        if s >= n:
            break
    else:
        break
print((ans + sum(a[s:])))

+import sys + +input = sys.stdin.readline +from operator import itemgetter -bc.sort(key=lambda x: x[1], reverse=True) +bc.sort(key=itemgetter(1), reverse=True) +ans = 0 -        for j in range(s, min(t, s + bc[i][0])): -            a[j] = bc[i][1] -        s = min(t, s + bc[i][0]) +        cvt = min(t - s, bc[i][0]) +        ans += bc[i][1] * cvt +        s += cvt -print((sum(a))) +print((ans + sum(a[s:])))