Buggy python submission (verdict: Time Limit Exceeded):
n,m=[int(x) for x in input().rstrip().split()]
A=[int(x) for x in input().rstrip().split()]
now=[]
for i in range(m):
  b,c=[int(x) for x in input().rstrip().split()]
  A.extend([c]*b)
A.sort(reverse=True)
print(sum(A[:n]))



Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
from bisect import bisect_left
 
 
n, m = map(int, input().split())
a = list( map(int, input().split()))
a.sort()
 
bc = [tuple(map(int,input().split())) for i in range(m)]
bc = sorted(bc, reverse=True, key=lambda x: x[1])
 
i = 0
d = []
for b, c in bc:
    d.extend([c]*b)
    if len(d) >= n:
        break
 
a=a+d
a.sort(reverse=True)
print(sum(a[:n]))

#l.sort(reverse=True)
#A=A+l[:N]
#A.sort(reverse=True)

Buggy python submission (verdict: Time Limit Exceeded):

N,M=[int(x) for x in input().rstrip().split()]
A=[int(x) for x in input().rstrip().split()]
A.sort()
l=[0 for i in range(N)]
l1=[]
B=[[int(x) for x in input().rstrip().split() ]for i in range(M)]


for i in range(len(B)):
    A.sort()
    for j in range(B[i][0]):
        if A[j]<B[i][1]:
            A[j]=B[i][1]
print(sum(A))



#l.sort(reverse=True)
#A=A+l[:N]
#A.sort(reverse=True)



    




Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
from bisect import bisect_left
 
 
n, m = map(int, input().split())
a = list( map(int, input().split()))
a.sort()
 
bc = [tuple(map(int,input().split())) for i in range(m)]
bc = sorted(bc, reverse=True, key=lambda x: x[1])
 
i = 0
d = []
for b, c in bc:
    d.extend([c]*b)
    if len(d) >= n:
        break
 
a=a+d
a.sort(reverse=True)
print(sum(a[:n]))

#l.sort(reverse=True)
#A=A+l[:N]
#A.sort(reverse=True)

Buggy python submission (verdict: Time Limit Exceeded):

N,M=[int(x) for x in input().rstrip().split()]
A=[int(x) for x in input().rstrip().split()]
l=[0 for i in range(N)]
l1=[]

for i in range(M):
    l.sort()
    b,c=[int(x) for x in input().rstrip().split()]
    l1=[c]*b
    for j in range(b):
        if l[j]<l1[j]:
            l[j]=l1[j]
        



l.sort(reverse=True)
A=A+l[:N]
A.sort(reverse=True)
print(sum(A[:N]))


    




Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
from bisect import bisect_left
 
 
n, m = map(int, input().split())
a = list( map(int, input().split()))
a.sort()
 
bc = [tuple(map(int,input().split())) for i in range(m)]
bc = sorted(bc, reverse=True, key=lambda x: x[1])
 
i = 0
d = []
for b, c in bc:
    d.extend([c]*b)
    if len(d) >= n:
        break
 
a=a+d
a.sort(reverse=True)
print(sum(a[:n]))

#l.sort(reverse=True)
#A=A+l[:N]
#A.sort(reverse=True)

Buggy python submission (verdict: Time Limit Exceeded):

N,M=[int(x) for x in input().rstrip().split()]
A=[int(x) for x in input().rstrip().split()]
l=[]
l1=[]

for i in range(M):
    b,c=[int(x) for x in input().rstrip().split()]
    l1=[c]*b
    l=l+l1
l.sort(reverse=True)
A=A+l[:N]
A.sort(reverse=True)
print(sum(A[:N]))


    




Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
from bisect import bisect_left
 
 
n, m = map(int, input().split())
a = list( map(int, input().split()))
a.sort()
 
bc = [tuple(map(int,input().split())) for i in range(m)]
bc = sorted(bc, reverse=True, key=lambda x: x[1])
 
i = 0
d = []
for b, c in bc:
    d.extend([c]*b)
    if len(d) >= n:
        break
 
a=a+d
a.sort(reverse=True)
print(sum(a[:n]))

#l.sort(reverse=True)
#A=A+l[:N]
#A.sort(reverse=True)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=[int(x) for x in input().rstrip().split()]
A=[int(x) for x in input().rstrip().split()]
l=[]
l1=[]

for i in range(M):
    b,c=[int(x) for x in input().rstrip().split()]
    l1=[c for i in range(b)]
    l=l+l1
l.sort(reverse=True)
A=A+l[:N]
A.sort(reverse=True)
print(sum(A[:N]))

    




Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
from bisect import bisect_left
 
 
n, m = map(int, input().split())
a = list( map(int, input().split()))
a.sort()
 
bc = [tuple(map(int,input().split())) for i in range(m)]
bc = sorted(bc, reverse=True, key=lambda x: x[1])
 
i = 0
d = []
for b, c in bc:
    d.extend([c]*b)
    if len(d) >= n:
        break
 
a=a+d
a.sort(reverse=True)
print(sum(a[:n]))

#l.sort(reverse=True)
#A=A+l[:N]
#A.sort(reverse=True)