Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]
# target = sorted(target, key = lambda x:x[1], reverse=True)
# print(target)

'''
4 4
1 3
2 2
1 1
2 4


'''


for t in target:
    A.extend([t[1]] * t[0])
A.sort(reverse=True)

print(sum(A[:N]))


Fixed submission:
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]
target = sorted(target, key = lambda x:x[1], reverse=True)
# print(target)

'''
4 4
1 3
2 2
1 1
2 4


'''


for t in target:
    A.extend([t[1]] * t[0])
    if len(A) > N * 2:
        break
A.sort(reverse=True)

print(sum(A[:N]))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]
#target = sorted(target, key = lambda x:x[1], reverse=True)
#print(target)

'''
4 4
1 3
2 2
1 1
2 4


'''

tmp = []

for t in target:
    for i in range(t[0]):
        tmp.append(t[1])
tmp.sort(reverse=True)
A.extend(tmp)
A.sort(reverse=True)

print(sum(A[:N]))


Fixed submission:
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]
target = sorted(target, key = lambda x:x[1], reverse=True)
# print(target)

'''
4 4
1 3
2 2
1 1
2 4


'''


for t in target:
    A.extend([t[1]] * t[0])
    if len(A) > N * 2:
        break
A.sort(reverse=True)

print(sum(A[:N]))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]

'''
4 4
1 3
2 2
1 1
2 4


'''
A.sort()

tmp = []

for t in target:
    for i in range(t[0]):
        tmp.append(t[1])
tmp.sort(reverse=True)


#print(A)
#print(tmp)
for i,a in enumerate(A):
    if i < len(tmp) and A[i] < tmp[i]:
        A[i] = tmp[i]
        #print(A)
    else:
        break

print(sum(A))


Fixed submission:
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]
target = sorted(target, key = lambda x:x[1], reverse=True)
# print(target)

'''
4 4
1 3
2 2
1 1
2 4


'''


for t in target:
    A.extend([t[1]] * t[0])
    if len(A) > N * 2:
        break
A.sort(reverse=True)

print(sum(A[:N]))

Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]

'''
4 4
1 3
2 2
1 1
2 4


'''
A.sort()

tmp = []

for t in target:
    for i in range(t[0]):
        tmp.append(t[1])
tmp.sort(reverse=True)


#print(A)
#print(tmp)
for i,a in enumerate(A):
    if A[i] < tmp[i] and i < len(tmp) :
        A[i] = tmp[i]
        #print(A)
    else:
        break

print(sum(A))


Fixed submission:
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]
target = sorted(target, key = lambda x:x[1], reverse=True)
# print(target)

'''
4 4
1 3
2 2
1 1
2 4


'''


for t in target:
    A.extend([t[1]] * t[0])
    if len(A) > N * 2:
        break
A.sort(reverse=True)

print(sum(A[:N]))

Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]

'''
4 4
1 3
2 2
1 1
2 4


'''
A.sort()

tmp = []

for t in target:
    for i in range(t[0]):
        tmp.append(t[1])
tmp.sort(reverse=True)


#print(A)
#print(tmp)
for i,a in enumerate(A):
    if A[i] < tmp[i]:
        A[i] = tmp[i]
        #print(A)
    else:
        break

print(sum(A))


Fixed submission:
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]
target = sorted(target, key = lambda x:x[1], reverse=True)
# print(target)

'''
4 4
1 3
2 2
1 1
2 4


'''


for t in target:
    A.extend([t[1]] * t[0])
    if len(A) > N * 2:
        break
A.sort(reverse=True)

print(sum(A[:N]))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]

'''
4 4
1 3
2 2
1 1
2 4


'''
A.sort()
#print(A)
for t in target:
    #print(t)
    for i, e in enumerate(A[0:t[0]]):
        if e < t[1]:
            A[i] = t[1]
            #print(i)
            #print(e)
        else:
            break
    A.sort()
#print(A)
print(sum(A))


Fixed submission:
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
target = [list(map(int, input().split())) for i in range(M)]
target = sorted(target, key = lambda x:x[1], reverse=True)
# print(target)

'''
4 4
1 3
2 2
1 1
2 4


'''


for t in target:
    A.extend([t[1]] * t[0])
    if len(A) > N * 2:
        break
A.sort(reverse=True)

print(sum(A[:N]))