import bisect
 
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = []
for i in range(m):
    bc.append(list(map(int, input().split())))
bc.sort(key = lambda x: x[1], reverse = True)
a.sort(reverse = True)
count = 0 
count2 = 0
a2 = [0]
for i in range(n):
    a2.append(a2[-1] + a[i])
a.reverse()
sum_a = 0
for i in range(m):
    num = bc[i][1]
    num2 = bc[i][0]
    temp = n - bisect.bisect_left(a, num)
    count += temp
    count2 += temp
    temp2 = min(num2, n - count2)
    sum_a += num * temp2
    count2 += temp2
    if count2 == n:
        break
    count -= temp
    count2 -= temp
count3 = n - (count2 - count)
sum_a += a2[count3]
print(sum_a) import bisect bisect n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bc = [] bc [] for i in range(m):
    bc.append(list(map(int, input().split()))) i range(m) range m bc.append(list(map(int, input().split()))) bc.append bc append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bc.sort(key = lambda x: x[1], reverse = True) bc.sort bc sort key = lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse = True reverse True a.sort(reverse = True) a.sort a sort reverse = True reverse True count = 0 count 0 count2 = 0 count2 0 a2 = [0] a2 [0] 0 for i in range(n):
    a2.append(a2[-1] + a[i]) i range(n) range n a2.append(a2[-1] + a[i]) a2.append a2 append a2[-1] + a[i] a2[-1] a2 -1 a[i] a i a.reverse() a.reverse a reverse sum_a = 0 sum_a 0 for i in range(m):
    num = bc[i][1]
    num2 = bc[i][0]
    temp = n - bisect.bisect_left(a, num)
    count += temp
    count2 += temp
    temp2 = min(num2, n - count2)
    sum_a += num * temp2
    count2 += temp2
    if count2 == n:
        break
    count -= temp
    count2 -= temp i range(m) range m num = bc[i][1] num bc[i][1] [i] bc i 1 num2 = bc[i][0] num2 bc[i][0] [i] bc i 0 temp = n - bisect.bisect_left(a, num) temp n - bisect.bisect_left(a, num) n bisect.bisect_left(a, num) bisect.bisect_left bisect bisect_left a num count += temp count temp count2 += temp count2 temp temp2 = min(num2, n - count2) temp2 min(num2, n - count2) min num2 n - count2 n count2 sum_a += num * temp2 sum_a num * temp2 num temp2 count2 += temp2 count2 temp2 if count2 == n:
        break
     count2 == n count2 n break count -= temp count temp count2 -= temp count2 temp count3 = n - (count2 - count) count3 n - (count2 - count) n count2 - count count2 count sum_a += a2[count3] sum_a a2[count3] a2 count3 print(sum_a) print sum_a n, m = map(int, input().split()) map(int, input().split()) n count2 = 0 0 count2 num = bc[i][1] bc[i][1] num a2 = [0] [0] a2 a = list(map(int, input().split())) list(map(int, input().split())) a num2 = bc[i][0] bc[i][0] num2 count3 = n - (count2 - count) n - (count2 - count) count3 count2 += temp2 temp2 count2 sum_a = 0 0 sum_a m = map(int, input().split()) map(int, input().split()) m temp = n - bisect.bisect_left(a, num) n - bisect.bisect_left(a, num) temp sum_a += num * temp2 num * temp2 sum_a count2 += temp temp count2 count -= temp temp count count = 0 0 count sum_a += a2[count3] a2[count3] sum_a bc = [] [] bc temp2 = min(num2, n - count2) min(num2, n - count2) temp2 count += temp temp count count2 -= temp temp count2
import bisect
 
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = []
for i in range(m):
    bc.append(list(map(int, input().split())))
bc.sort(key = lambda x: x[1], reverse = True)
a.sort(reverse = True)
count = 0 
count2 = 0
a2 = [0]
for i in range(n):
    a2.append(a2[-1] + a[i])
a.reverse()
sum_a = 0
for i in range(m):
    num = bc[i][1]
    num2 = bc[i][0]
    temp = n - bisect.bisect_left(a, num)
    count += temp
    count2 += temp
    temp2 = min(num2, n - count2)
    sum_a += num * temp2
    count2 += temp2
    if count2 == n:
        break
    count -= temp
    count2 -= temp
count3 = n - (count2 - count)
sum_a += a2[count3]
print(sum_a)