import heapq


change = []
n, m = map(int, input().split())
a = [-1 * int(i) for i in input().split()]
for i in range(m):
    b, c = map(int, input().split())
    change.append([-c, b])

total = 0
heapq.heapify(change)
heapq.heapify(a)
flg = False
cnt = 0
while cnt < n:
    if change:
        atmp = -1 * a[0]
        btmp = -1 * change[0][0]
        if atmp <= btmp:
            b, c = heapq.heappop(change)
            while c > 0 and cnt < n:
                total -= b
                c -= 1
                cnt += 1
        else:
            aa = heapq.heappop(a)
            total -= aa
            cnt += 1
    else:
        aa = heapq.heappop(a)
        total -= aa
        cnt += 1
        
print(total) import heapq heapq change = [] change [] n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m -1 * int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() -1 * int(i) -1 int(i) int i a = [-1 * int(i) for i in input().split()] a [-1 * int(i) for i in input().split()] for i in range(m):
    b, c = map(int, input().split())
    change.append([-c, b]) i range(m) range m b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c change.append([-c, b]) change.append change append [-c, b] -c c b total = 0 total 0 heapq.heapify(change) heapq.heapify heapq heapify change heapq.heapify(a) heapq.heapify heapq heapify a flg = False flg False cnt = 0 cnt 0 while cnt < n:
    if change:
        atmp = -1 * a[0]
        btmp = -1 * change[0][0]
        if atmp <= btmp:
            b, c = heapq.heappop(change)
            while c > 0 and cnt < n:
                total -= b
                c -= 1
                cnt += 1
        else:
            aa = heapq.heappop(a)
            total -= aa
            cnt += 1
    else:
        aa = heapq.heappop(a)
        total -= aa
        cnt += 1
         cnt < n cnt n if change:
        atmp = -1 * a[0]
        btmp = -1 * change[0][0]
        if atmp <= btmp:
            b, c = heapq.heappop(change)
            while c > 0 and cnt < n:
                total -= b
                c -= 1
                cnt += 1
        else:
            aa = heapq.heappop(a)
            total -= aa
            cnt += 1
    else:
        aa = heapq.heappop(a)
        total -= aa
        cnt += 1
         change atmp = -1 * a[0] atmp -1 * a[0] -1 a[0] a 0 btmp = -1 * change[0][0] btmp -1 * change[0][0] -1 change[0][0] [0] change 0 0 if atmp <= btmp:
            b, c = heapq.heappop(change)
            while c > 0 and cnt < n:
                total -= b
                c -= 1
                cnt += 1
        else:
            aa = heapq.heappop(a)
            total -= aa
            cnt += 1
     atmp <= btmp atmp btmp b, c = heapq.heappop(change) b heapq.heappop(change) heapq.heappop heapq heappop change c while c > 0 and cnt < n:
                total -= b
                c -= 1
                cnt += 1
         c > 0 and cnt < n c > 0 c 0 cnt < n cnt n total -= b total b c -= 1 c 1 cnt += 1 cnt 1 aa = heapq.heappop(a) aa heapq.heappop(a) heapq.heappop heapq heappop a total -= aa total aa cnt += 1 cnt 1 aa = heapq.heappop(a) aa heapq.heappop(a) heapq.heappop heapq heappop a total -= aa total aa cnt += 1 cnt 1 print(total) print total n, m = map(int, input().split()) map(int, input().split()) n aa = heapq.heappop(a) heapq.heappop(a) aa total -= b b total total -= aa aa total m = map(int, input().split()) map(int, input().split()) m flg = False False flg cnt = 0 0 cnt c = map(int, input().split()) map(int, input().split()) c aa = heapq.heappop(a) heapq.heappop(a) aa total = 0 0 total change = [] [] change total -= aa aa total cnt += 1 1 cnt b, c = map(int, input().split()) map(int, input().split()) b atmp = -1 * a[0] -1 * a[0] atmp c -= 1 1 c btmp = -1 * change[0][0] -1 * change[0][0] btmp cnt += 1 1 cnt cnt += 1 1 cnt c = heapq.heappop(change) heapq.heappop(change) c b, c = heapq.heappop(change) heapq.heappop(change) b a = [-1 * int(i) for i in input().split()] [-1 * int(i) for i in input().split()] a
import heapq


change = []
n, m = map(int, input().split())
a = [-1 * int(i) for i in input().split()]
for i in range(m):
    b, c = map(int, input().split())
    change.append([-c, b])

total = 0
heapq.heapify(change)
heapq.heapify(a)
flg = False
cnt = 0
while cnt < n:
    if change:
        atmp = -1 * a[0]
        btmp = -1 * change[0][0]
        if atmp <= btmp:
            b, c = heapq.heappop(change)
            while c > 0 and cnt < n:
                total -= b
                c -= 1
                cnt += 1
        else:
            aa = heapq.heappop(a)
            total -= aa
            cnt += 1
    else:
        aa = heapq.heappop(a)
        total -= aa
        cnt += 1
        
print(total)