import numpy as np

n, m = map(int, input().split())
a = np.array(sorted(list(map(int, input().split()))), dtype=np.int64)
bc = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: -x[1])

p = 0
for b, c  in bc:
    a[p:p+b] = np.maximum(a[p:p+b], c)
    p += b
print(np.sum(a)) import numpy as np numpy n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m a = np.array(sorted(list(map(int, input().split()))), dtype=np.int64) a np.array(sorted(list(map(int, input().split()))), dtype=np.int64) np.array np array sorted(list(map(int, input().split()))) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dtype=np.int64 dtype np.int64 np int64 list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bc = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: -x[1]) bc sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: -x[1]) sorted [list(map(int, input().split())) for _ in range(m)] key=lambda x: -x[1] key lambda x: -x[1] -x[1] x[1] x 1 x p = 0 p 0 for b, c  in bc:
    a[p:p+b] = np.maximum(a[p:p+b], c)
    p += b b c bc a[p:p+b] = np.maximum(a[p:p+b], c) a[p:p+b] a p:p+b p p+b p b np.maximum(a[p:p+b], c) np.maximum np maximum a[p:p+b] a p:p+b p p+b p b c p += b p b print(np.sum(a)) print np.sum(a) np.sum np sum a m = map(int, input().split()) map(int, input().split()) m p = 0 0 p p += b b p a = np.array(sorted(list(map(int, input().split()))), dtype=np.int64) np.array(sorted(list(map(int, input().split()))), dtype=np.int64) a n, m = map(int, input().split()) map(int, input().split()) n bc = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: -x[1]) sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: -x[1]) bc
import numpy as np

n, m = map(int, input().split())
a = np.array(sorted(list(map(int, input().split()))), dtype=np.int64)
bc = sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: -x[1])

p = 0
for b, c  in bc:
    a[p:p+b] = np.maximum(a[p:p+b], c)
    p += b
print(np.sum(a))