I=lambda:list(map(int,input().split()))

n,m=I()

a=I()

a.sort(reverse=True)

qq=[I() for i in range(m)]

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

ans=0

for x,y in qq:

    for j in range(x):

        if not a:

            break

        aa=a.pop()

        ans+=max(aa,y)

ans+=sum(a)

print(ans)

        
I=lambda : list(map(int,input().split()))

n,m = I()

l=I();s=sum(l);l.sort();d=[]

for _ in range(m):

    b,c=I()

    d.append([c,b])

p=s=0    

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

    while i[1]:

        if p>=n or l[p]>=i[0]:

            break

        i[1]-=1

        s+=i[0]

        p+=1

    if p>=n:

        break

s+=sum(l[p:])

print(s)
I = lambda: list(map(int, input().split()))
n, m = I()
a = I()
a.sort(reverse=True)
qq = [I() for i in range(m)]
qq.sort(key=lambda x: x[1], reverse=True)
ans = 0
for x, y in qq:
    for j in range(x):
        if not a:
            break
        aa = a.pop()
        ans += max(aa, y)
ans += sum(a)
print(ans)

I = lambda: list(map(int, input().split()))
n, m = I()
l = I()
s = sum(l)
l.sort()
d = []
for _ in range(m):
    b, c = I()
    d.append([c, b])
p = s = 0
for i in sorted(d, reverse=True):
    while i[1]:
        if p >= n or l[p] >= i[0]:
            break
        i[1] -= 1
        s += i[0]
        p += 1
    if p >= n:
        break
s += sum(l[p:])
print(s)

-a = I() -a.sort(reverse=True) -qq = [I() for i in range(m)] -qq.sort(key=lambda x: x[1], reverse=True) -ans = 0 -for x, y in qq: -    for j in range(x): -        if not a: +l = I() +s = sum(l) +l.sort() +d = [] +for _ in range(m): +    b, c = I() +    d.append([c, b]) +p = s = 0 +for i in sorted(d, reverse=True): +    while i[1]: +        if p >= n or l[p] >= i[0]: -        aa = a.pop() -        ans += max(aa, y) -ans += sum(a) -print(ans) +        i[1] -= 1 +        s += i[0] +        p += 1 +    if p >= n: +        break +s += sum(l[p:]) +print(s)