import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = [int(_) for _ in input().split()]
cb = [0] * m
for i in range(m):
    bb, cc = map(int, input().split())
    cb[i] = (cc, bb)

cb.sort(reverse=True)

arr = []
l = 0
for i in range(m):
    if l + cb[i][1] > 10**5:
        add = 10**5 - l
        for j in range(add):
            arr.append(cb[i][0])
        break
    else:
        for j in range(cb[i][1]):
            arr.append(cb[i][0])
        l += cb[i][1]

a = a + arr
a.sort(reverse=True)
print(sum(a[0:n])) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m int(_) for _ in input().split() for _ in input().split() _ input().split() ().split () input split for _ in input().split() int(_) int _ a = [int(_) for _ in input().split()] a [int(_) for _ in input().split()] cb = [0] * m cb [0] * m [0] 0 m for i in range(m):
    bb, cc = map(int, input().split())
    cb[i] = (cc, bb) i range(m) range m bb, cc = map(int, input().split()) bb map(int, input().split()) map int input().split() ().split () input split cc cb[i] = (cc, bb) cb[i] cb i (cc, bb) cc bb cb.sort(reverse=True) cb.sort cb sort reverse=True reverse True arr = [] arr [] l = 0 l 0 for i in range(m):
    if l + cb[i][1] > 10**5:
        add = 10**5 - l
        for j in range(add):
            arr.append(cb[i][0])
        break
    else:
        for j in range(cb[i][1]):
            arr.append(cb[i][0])
        l += cb[i][1] i range(m) range m if l + cb[i][1] > 10**5:
        add = 10**5 - l
        for j in range(add):
            arr.append(cb[i][0])
        break
    else:
        for j in range(cb[i][1]):
            arr.append(cb[i][0])
        l += cb[i][1] l + cb[i][1] > 10**5 l + cb[i][1] l cb[i][1] [i] cb i 1 10**5 10 5 add = 10**5 - l add 10**5 - l 10**5 10 5 l for j in range(add):
            arr.append(cb[i][0])
         j range(add) range add arr.append(cb[i][0]) arr.append arr append cb[i][0] [i] cb i 0 break for j in range(cb[i][1]):
            arr.append(cb[i][0])
         j range(cb[i][1]) range cb[i][1] [i] cb i 1 arr.append(cb[i][0]) arr.append arr append cb[i][0] [i] cb i 0 l += cb[i][1] l cb[i][1] [i] cb i 1 a = a + arr a a + arr a arr a.sort(reverse=True) a.sort a sort reverse=True reverse True print(sum(a[0:n])) print sum(a[0:n]) sum a[0:n] a 0:n 0 n m = map(int, input().split()) map(int, input().split()) m l += cb[i][1] cb[i][1] l cc = map(int, input().split()) map(int, input().split()) cc cb = [0] * m [0] * m cb n, m = map(int, input().split()) map(int, input().split()) n a = a + arr a + arr a input = sys.stdin.readline sys.stdin.readline input arr = [] [] arr l = 0 0 l a = [int(_) for _ in input().split()] [int(_) for _ in input().split()] a add = 10**5 - l 10**5 - l add bb, cc = map(int, input().split()) map(int, input().split()) bb
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
a = [int(_) for _ in input().split()]
cb = [0] * m
for i in range(m):
    bb, cc = map(int, input().split())
    cb[i] = (cc, bb)

cb.sort(reverse=True)

arr = []
l = 0
for i in range(m):
    if l + cb[i][1] > 10**5:
        add = 10**5 - l
        for j in range(add):
            arr.append(cb[i][0])
        break
    else:
        for j in range(cb[i][1]):
            arr.append(cb[i][0])
        l += cb[i][1]

a = a + arr
a.sort(reverse=True)
print(sum(a[0:n]))