n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
rep = sorted([tuple(map(int, input().split())) for i in range(m)], key= lambda x: -x[1])
i = 0
for b, c in rep:
    while i < n and b:
        if a[i] < c:
            a[i] = c
            i += 1
            b -= 1
        else:
            break
print(sum(a)) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m a = sorted(list(map(int, input().split()))) a sorted(list(map(int, input().split()))) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split tuple(map(int, input().split())) for i in range(m) for i in range(m) i range(m) range m for i in range(m) tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split rep = sorted([tuple(map(int, input().split())) for i in range(m)], key= lambda x: -x[1]) rep sorted([tuple(map(int, input().split())) for i in range(m)], key= lambda x: -x[1]) sorted [tuple(map(int, input().split())) for i in range(m)] key= lambda x: -x[1] key lambda x: -x[1] -x[1] x[1] x 1 x i = 0 i 0 for b, c in rep:
    while i < n and b:
        if a[i] < c:
            a[i] = c
            i += 1
            b -= 1
        else:
            break b c rep while i < n and b:
        if a[i] < c:
            a[i] = c
            i += 1
            b -= 1
        else:
            break i < n and b i < n i n b if a[i] < c:
            a[i] = c
            i += 1
            b -= 1
        else:
            break a[i] < c a[i] a i c a[i] = c a[i] a i c i += 1 i 1 b -= 1 b 1 break print(sum(a)) print sum(a) sum a b -= 1 1 b m = map(int, input().split()) map(int, input().split()) m a = sorted(list(map(int, input().split()))) sorted(list(map(int, input().split()))) a rep = sorted([tuple(map(int, input().split())) for i in range(m)], key= lambda x: -x[1]) sorted([tuple(map(int, input().split())) for i in range(m)], key= lambda x: -x[1]) rep n, m = map(int, input().split()) map(int, input().split()) n i = 0 0 i i += 1 1 i
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
rep = sorted([tuple(map(int, input().split())) for i in range(m)], key= lambda x: -x[1])
i = 0
for b, c in rep:
    while i < n and b:
        if a[i] < c:
            a[i] = c
            i += 1
            b -= 1
        else:
            break
print(sum(a))